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-audio-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> |
| 36 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 37 | #include <linux/slab.h> |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 38 | #include <linux/uaccess.h> |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 39 | |
| 40 | MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards"); |
| 41 | MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>"); |
| 42 | MODULE_LICENSE("GPL"); |
| 43 | |
Linus Torvalds | f063a0c | 2010-10-28 12:13:00 -0700 | [diff] [blame] | 44 | static int _intr_msk = FLD_AUD_SRC_RISCI1 | FLD_AUD_SRC_OF | |
| 45 | FLD_AUD_SRC_SYNC | FLD_AUD_SRC_OPC_ERR; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 46 | |
| 47 | int cx25821_sram_channel_setup_upstream_audio(struct cx25821_dev *dev, |
| 48 | struct sram_channel *ch, |
| 49 | unsigned int bpl, u32 risc) |
| 50 | { |
| 51 | unsigned int i, lines; |
| 52 | u32 cdt; |
| 53 | |
| 54 | if (ch->cmds_start == 0) { |
| 55 | cx_write(ch->ptr1_reg, 0); |
| 56 | cx_write(ch->ptr2_reg, 0); |
| 57 | cx_write(ch->cnt2_reg, 0); |
| 58 | cx_write(ch->cnt1_reg, 0); |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | bpl = (bpl + 7) & ~7; /* alignment */ |
| 63 | cdt = ch->cdt; |
| 64 | lines = ch->fifo_size / bpl; |
| 65 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 66 | if (lines > 3) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 67 | lines = 3; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 68 | |
| 69 | BUG_ON(lines < 2); |
| 70 | |
| 71 | /* write CDT */ |
| 72 | for (i = 0; i < lines; i++) { |
| 73 | cx_write(cdt + 16 * i, ch->fifo_start + bpl * i); |
| 74 | cx_write(cdt + 16 * i + 4, 0); |
| 75 | cx_write(cdt + 16 * i + 8, 0); |
| 76 | cx_write(cdt + 16 * i + 12, 0); |
| 77 | } |
| 78 | |
| 79 | /* write CMDS */ |
| 80 | cx_write(ch->cmds_start + 0, risc); |
| 81 | |
| 82 | cx_write(ch->cmds_start + 4, 0); |
| 83 | cx_write(ch->cmds_start + 8, cdt); |
| 84 | cx_write(ch->cmds_start + 12, AUDIO_CDT_SIZE_QW); |
| 85 | cx_write(ch->cmds_start + 16, ch->ctrl_start); |
| 86 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 87 | /* IQ size */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 88 | cx_write(ch->cmds_start + 20, AUDIO_IQ_SIZE_DW); |
| 89 | |
| 90 | for (i = 24; i < 80; i += 4) |
| 91 | cx_write(ch->cmds_start + i, 0); |
| 92 | |
| 93 | /* fill registers */ |
| 94 | cx_write(ch->ptr1_reg, ch->fifo_start); |
| 95 | cx_write(ch->ptr2_reg, cdt); |
| 96 | cx_write(ch->cnt2_reg, AUDIO_CDT_SIZE_QW); |
| 97 | cx_write(ch->cnt1_reg, AUDIO_CLUSTER_SIZE_QW - 1); |
| 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | static __le32 *cx25821_risc_field_upstream_audio(struct cx25821_dev *dev, |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 103 | __le32 *rp, |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 104 | dma_addr_t databuf_phys_addr, |
| 105 | unsigned int bpl, |
| 106 | int fifo_enable) |
| 107 | { |
| 108 | unsigned int line; |
| 109 | struct sram_channel *sram_ch = |
Leonid V. Fedorenchik | 81f4c8d | 2011-10-22 01:43:25 -0300 | [diff] [blame] | 110 | dev->channels[dev->_audio_upstream_channel].sram_channels; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 111 | int offset = 0; |
| 112 | |
| 113 | /* scan lines */ |
| 114 | for (line = 0; line < LINES_PER_AUDIO_BUFFER; line++) { |
| 115 | *(rp++) = cpu_to_le32(RISC_READ | RISC_SOL | RISC_EOL | bpl); |
| 116 | *(rp++) = cpu_to_le32(databuf_phys_addr + offset); |
| 117 | *(rp++) = cpu_to_le32(0); /* bits 63-32 */ |
| 118 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 119 | /* Check if we need to enable the FIFO |
| 120 | * after the first 3 lines. |
| 121 | * For the upstream audio channel, |
| 122 | * the risc engine will enable the FIFO */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 123 | if (fifo_enable && line == 2) { |
| 124 | *(rp++) = RISC_WRITECR; |
| 125 | *(rp++) = sram_ch->dma_ctl; |
| 126 | *(rp++) = sram_ch->fld_aud_fifo_en; |
| 127 | *(rp++) = 0x00000020; |
| 128 | } |
| 129 | |
| 130 | offset += AUDIO_LINE_SIZE; |
| 131 | } |
| 132 | |
| 133 | return rp; |
| 134 | } |
| 135 | |
| 136 | int cx25821_risc_buffer_upstream_audio(struct cx25821_dev *dev, |
| 137 | struct pci_dev *pci, |
| 138 | unsigned int bpl, unsigned int lines) |
| 139 | { |
| 140 | __le32 *rp; |
| 141 | int fifo_enable = 0; |
| 142 | int frame = 0, i = 0; |
| 143 | int frame_size = AUDIO_DATA_BUF_SZ; |
| 144 | int databuf_offset = 0; |
| 145 | int risc_flag = RISC_CNT_INC; |
| 146 | dma_addr_t risc_phys_jump_addr; |
| 147 | |
| 148 | /* Virtual address of Risc buffer program */ |
| 149 | rp = dev->_risc_virt_addr; |
| 150 | |
| 151 | /* sync instruction */ |
| 152 | *(rp++) = cpu_to_le32(RISC_RESYNC | AUDIO_SYNC_LINE); |
| 153 | |
| 154 | for (frame = 0; frame < NUM_AUDIO_FRAMES; frame++) { |
| 155 | databuf_offset = frame_size * frame; |
| 156 | |
| 157 | if (frame == 0) { |
| 158 | fifo_enable = 1; |
| 159 | risc_flag = RISC_CNT_RESET; |
| 160 | } else { |
| 161 | fifo_enable = 0; |
| 162 | risc_flag = RISC_CNT_INC; |
| 163 | } |
| 164 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 165 | /* Calculate physical jump address */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 166 | if ((frame + 1) == NUM_AUDIO_FRAMES) { |
| 167 | risc_phys_jump_addr = |
| 168 | dev->_risc_phys_start_addr + |
| 169 | RISC_SYNC_INSTRUCTION_SIZE; |
| 170 | } else { |
| 171 | risc_phys_jump_addr = |
| 172 | dev->_risc_phys_start_addr + |
| 173 | RISC_SYNC_INSTRUCTION_SIZE + |
| 174 | AUDIO_RISC_DMA_BUF_SIZE * (frame + 1); |
| 175 | } |
| 176 | |
| 177 | rp = cx25821_risc_field_upstream_audio(dev, rp, |
Leonid V. Fedorenchik | 72a52fc | 2011-10-22 01:43:27 -0300 | [diff] [blame^] | 178 | dev->_audiodata_buf_phys_addr + databuf_offset, |
| 179 | bpl, fifo_enable); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 180 | |
| 181 | if (USE_RISC_NOOP_AUDIO) { |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 182 | for (i = 0; i < NUM_NO_OPS; i++) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 183 | *(rp++) = cpu_to_le32(RISC_NOOP); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 184 | } |
| 185 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 186 | /* Loop to (Nth)FrameRISC or to Start of Risc program & |
| 187 | * generate IRQ */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 188 | *(rp++) = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | risc_flag); |
| 189 | *(rp++) = cpu_to_le32(risc_phys_jump_addr); |
| 190 | *(rp++) = cpu_to_le32(0); |
| 191 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 192 | /* Recalculate virtual address based on frame index */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 193 | rp = dev->_risc_virt_addr + RISC_SYNC_INSTRUCTION_SIZE / 4 + |
Leonid V. Fedorenchik | 81f4c8d | 2011-10-22 01:43:25 -0300 | [diff] [blame] | 194 | (AUDIO_RISC_DMA_BUF_SIZE * (frame + 1) / 4); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | return 0; |
| 198 | } |
| 199 | |
| 200 | void cx25821_free_memory_audio(struct cx25821_dev *dev) |
| 201 | { |
| 202 | if (dev->_risc_virt_addr) { |
| 203 | pci_free_consistent(dev->pci, dev->_audiorisc_size, |
| 204 | dev->_risc_virt_addr, dev->_risc_phys_addr); |
| 205 | dev->_risc_virt_addr = NULL; |
| 206 | } |
| 207 | |
| 208 | if (dev->_audiodata_buf_virt_addr) { |
| 209 | pci_free_consistent(dev->pci, dev->_audiodata_buf_size, |
| 210 | dev->_audiodata_buf_virt_addr, |
| 211 | dev->_audiodata_buf_phys_addr); |
| 212 | dev->_audiodata_buf_virt_addr = NULL; |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | void cx25821_stop_upstream_audio(struct cx25821_dev *dev) |
| 217 | { |
| 218 | struct sram_channel *sram_ch = |
Leonid V. Fedorenchik | 81f4c8d | 2011-10-22 01:43:25 -0300 | [diff] [blame] | 219 | dev->channels[AUDIO_UPSTREAM_SRAM_CHANNEL_B].sram_channels; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 220 | u32 tmp = 0; |
| 221 | |
| 222 | if (!dev->_audio_is_running) { |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 223 | printk(KERN_DEBUG |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 224 | pr_fmt("No audio file is currently running so return!\n")); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 225 | return; |
| 226 | } |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 227 | /* Disable RISC interrupts */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 228 | cx_write(sram_ch->int_msk, 0); |
| 229 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 230 | /* Turn OFF risc and fifo enable in AUD_DMA_CNTRL */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 231 | tmp = cx_read(sram_ch->dma_ctl); |
| 232 | cx_write(sram_ch->dma_ctl, |
| 233 | tmp & ~(sram_ch->fld_aud_fifo_en | sram_ch->fld_aud_risc_en)); |
| 234 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 235 | /* Clear data buffer memory */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 236 | if (dev->_audiodata_buf_virt_addr) |
| 237 | memset(dev->_audiodata_buf_virt_addr, 0, |
| 238 | dev->_audiodata_buf_size); |
| 239 | |
| 240 | dev->_audio_is_running = 0; |
| 241 | dev->_is_first_audio_frame = 0; |
| 242 | dev->_audioframe_count = 0; |
| 243 | dev->_audiofile_status = END_OF_FILE; |
| 244 | |
Ilia Mirkin | b009178 | 2011-03-13 00:28:58 -0500 | [diff] [blame] | 245 | kfree(dev->_irq_audio_queues); |
| 246 | dev->_irq_audio_queues = NULL; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 247 | |
Ilia Mirkin | b009178 | 2011-03-13 00:28:58 -0500 | [diff] [blame] | 248 | kfree(dev->_audiofilename); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | void cx25821_free_mem_upstream_audio(struct cx25821_dev *dev) |
| 252 | { |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 253 | if (dev->_audio_is_running) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 254 | cx25821_stop_upstream_audio(dev); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 255 | |
| 256 | cx25821_free_memory_audio(dev); |
| 257 | } |
| 258 | |
| 259 | int cx25821_get_audio_data(struct cx25821_dev *dev, |
| 260 | struct sram_channel *sram_ch) |
| 261 | { |
| 262 | struct file *myfile; |
| 263 | int frame_index_temp = dev->_audioframe_index; |
| 264 | int i = 0; |
| 265 | int line_size = AUDIO_LINE_SIZE; |
| 266 | int frame_size = AUDIO_DATA_BUF_SZ; |
| 267 | int frame_offset = frame_size * frame_index_temp; |
| 268 | ssize_t vfs_read_retval = 0; |
| 269 | char mybuf[line_size]; |
| 270 | loff_t file_offset = dev->_audioframe_count * frame_size; |
| 271 | loff_t pos; |
| 272 | mm_segment_t old_fs; |
| 273 | |
| 274 | if (dev->_audiofile_status == END_OF_FILE) |
| 275 | return 0; |
| 276 | |
| 277 | myfile = filp_open(dev->_audiofilename, O_RDONLY | O_LARGEFILE, 0); |
| 278 | |
| 279 | if (IS_ERR(myfile)) { |
| 280 | const int open_errno = -PTR_ERR(myfile); |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 281 | pr_err("%s(): ERROR opening file(%s) with errno = %d!\n", |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 282 | __func__, dev->_audiofilename, open_errno); |
| 283 | return PTR_ERR(myfile); |
| 284 | } else { |
| 285 | if (!(myfile->f_op)) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 286 | pr_err("%s(): File has no file operations registered!\n", |
Leonid V. Fedorenchik | 81f4c8d | 2011-10-22 01:43:25 -0300 | [diff] [blame] | 287 | __func__); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 288 | filp_close(myfile, NULL); |
| 289 | return -EIO; |
| 290 | } |
| 291 | |
| 292 | if (!myfile->f_op->read) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 293 | pr_err("%s(): File has no READ operations registered!\n", |
Leonid V. Fedorenchik | 81f4c8d | 2011-10-22 01:43:25 -0300 | [diff] [blame] | 294 | __func__); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 295 | filp_close(myfile, NULL); |
| 296 | return -EIO; |
| 297 | } |
| 298 | |
| 299 | pos = myfile->f_pos; |
| 300 | old_fs = get_fs(); |
| 301 | set_fs(KERNEL_DS); |
| 302 | |
| 303 | for (i = 0; i < dev->_audio_lines_count; i++) { |
| 304 | pos = file_offset; |
| 305 | |
Leonid V. Fedorenchik | 72a52fc | 2011-10-22 01:43:27 -0300 | [diff] [blame^] | 306 | vfs_read_retval = vfs_read(myfile, mybuf, line_size, |
| 307 | &pos); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 308 | |
| 309 | if (vfs_read_retval > 0 && vfs_read_retval == line_size |
| 310 | && dev->_audiodata_buf_virt_addr != NULL) { |
| 311 | memcpy((void *)(dev->_audiodata_buf_virt_addr + |
| 312 | frame_offset / 4), mybuf, |
Leonid V. Fedorenchik | 81f4c8d | 2011-10-22 01:43:25 -0300 | [diff] [blame] | 313 | vfs_read_retval); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | file_offset += vfs_read_retval; |
| 317 | frame_offset += vfs_read_retval; |
| 318 | |
| 319 | if (vfs_read_retval < line_size) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 320 | pr_info("Done: exit %s() since no more bytes to read from Audio file\n", |
| 321 | __func__); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 322 | break; |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | if (i > 0) |
| 327 | dev->_audioframe_count++; |
| 328 | |
Leonid V. Fedorenchik | 72a52fc | 2011-10-22 01:43:27 -0300 | [diff] [blame^] | 329 | dev->_audiofile_status = (vfs_read_retval == line_size) ? |
| 330 | IN_PROGRESS : END_OF_FILE; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 331 | |
| 332 | set_fs(old_fs); |
| 333 | filp_close(myfile, NULL); |
| 334 | } |
| 335 | |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | static void cx25821_audioups_handler(struct work_struct *work) |
| 340 | { |
Leonid V. Fedorenchik | 72a52fc | 2011-10-22 01:43:27 -0300 | [diff] [blame^] | 341 | struct cx25821_dev *dev = container_of(work, struct cx25821_dev, |
| 342 | _audio_work_entry); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 343 | |
| 344 | if (!dev) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 345 | pr_err("ERROR %s(): since container_of(work_struct) FAILED!\n", |
Leonid V. Fedorenchik | 81f4c8d | 2011-10-22 01:43:25 -0300 | [diff] [blame] | 346 | __func__); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 347 | return; |
| 348 | } |
| 349 | |
Leonid V. Fedorenchik | 1531e88 | 2011-09-02 11:55:38 +0800 | [diff] [blame] | 350 | cx25821_get_audio_data(dev, dev->channels[dev->_audio_upstream_channel]. |
| 351 | sram_channels); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | int cx25821_openfile_audio(struct cx25821_dev *dev, |
| 355 | struct sram_channel *sram_ch) |
| 356 | { |
| 357 | struct file *myfile; |
| 358 | int i = 0, j = 0; |
| 359 | int line_size = AUDIO_LINE_SIZE; |
| 360 | ssize_t vfs_read_retval = 0; |
| 361 | char mybuf[line_size]; |
| 362 | loff_t pos; |
| 363 | loff_t offset = (unsigned long)0; |
| 364 | mm_segment_t old_fs; |
| 365 | |
| 366 | myfile = filp_open(dev->_audiofilename, O_RDONLY | O_LARGEFILE, 0); |
| 367 | |
| 368 | if (IS_ERR(myfile)) { |
| 369 | const int open_errno = -PTR_ERR(myfile); |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 370 | pr_err("%s(): ERROR opening file(%s) with errno = %d!\n", |
Leonid V. Fedorenchik | 81f4c8d | 2011-10-22 01:43:25 -0300 | [diff] [blame] | 371 | __func__, dev->_audiofilename, open_errno); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 372 | return PTR_ERR(myfile); |
| 373 | } else { |
| 374 | if (!(myfile->f_op)) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 375 | pr_err("%s(): File has no file operations registered!\n", |
Leonid V. Fedorenchik | 81f4c8d | 2011-10-22 01:43:25 -0300 | [diff] [blame] | 376 | __func__); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 377 | filp_close(myfile, NULL); |
| 378 | return -EIO; |
| 379 | } |
| 380 | |
| 381 | if (!myfile->f_op->read) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 382 | pr_err("%s(): File has no READ operations registered!\n", |
Leonid V. Fedorenchik | 81f4c8d | 2011-10-22 01:43:25 -0300 | [diff] [blame] | 383 | __func__); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 384 | filp_close(myfile, NULL); |
| 385 | return -EIO; |
| 386 | } |
| 387 | |
| 388 | pos = myfile->f_pos; |
| 389 | old_fs = get_fs(); |
| 390 | set_fs(KERNEL_DS); |
| 391 | |
| 392 | for (j = 0; j < NUM_AUDIO_FRAMES; j++) { |
| 393 | for (i = 0; i < dev->_audio_lines_count; i++) { |
| 394 | pos = offset; |
| 395 | |
Leonid V. Fedorenchik | 72a52fc | 2011-10-22 01:43:27 -0300 | [diff] [blame^] | 396 | vfs_read_retval = vfs_read(myfile, mybuf, |
| 397 | line_size, &pos); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 398 | |
Leonid V. Fedorenchik | 64dcb19 | 2011-10-22 01:43:26 -0300 | [diff] [blame] | 399 | if (vfs_read_retval > 0 && |
| 400 | vfs_read_retval == line_size && |
| 401 | dev->_audiodata_buf_virt_addr != NULL) { |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 402 | memcpy((void *)(dev-> |
| 403 | _audiodata_buf_virt_addr |
| 404 | + offset / 4), mybuf, |
| 405 | vfs_read_retval); |
| 406 | } |
| 407 | |
| 408 | offset += vfs_read_retval; |
| 409 | |
| 410 | if (vfs_read_retval < line_size) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 411 | pr_info("Done: exit %s() since no more bytes to read from Audio file\n", |
| 412 | __func__); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 413 | break; |
| 414 | } |
| 415 | } |
| 416 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 417 | if (i > 0) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 418 | dev->_audioframe_count++; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 419 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 420 | if (vfs_read_retval < line_size) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 421 | break; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 422 | } |
| 423 | |
Leonid V. Fedorenchik | 72a52fc | 2011-10-22 01:43:27 -0300 | [diff] [blame^] | 424 | dev->_audiofile_status = (vfs_read_retval == line_size) ? |
| 425 | IN_PROGRESS : END_OF_FILE; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 426 | |
| 427 | set_fs(old_fs); |
| 428 | myfile->f_pos = 0; |
| 429 | filp_close(myfile, NULL); |
| 430 | } |
| 431 | |
| 432 | return 0; |
| 433 | } |
| 434 | |
| 435 | static int cx25821_audio_upstream_buffer_prepare(struct cx25821_dev *dev, |
| 436 | struct sram_channel *sram_ch, |
| 437 | int bpl) |
| 438 | { |
| 439 | int ret = 0; |
| 440 | dma_addr_t dma_addr; |
| 441 | dma_addr_t data_dma_addr; |
| 442 | |
| 443 | cx25821_free_memory_audio(dev); |
| 444 | |
Leonid V. Fedorenchik | 72a52fc | 2011-10-22 01:43:27 -0300 | [diff] [blame^] | 445 | dev->_risc_virt_addr = pci_alloc_consistent(dev->pci, |
| 446 | dev->audio_upstream_riscbuf_size, &dma_addr); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 447 | dev->_risc_virt_start_addr = dev->_risc_virt_addr; |
| 448 | dev->_risc_phys_start_addr = dma_addr; |
| 449 | dev->_risc_phys_addr = dma_addr; |
| 450 | dev->_audiorisc_size = dev->audio_upstream_riscbuf_size; |
| 451 | |
| 452 | if (!dev->_risc_virt_addr) { |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 453 | printk(KERN_DEBUG |
Leonid V. Fedorenchik | 81f4c8d | 2011-10-22 01:43:25 -0300 | [diff] [blame] | 454 | pr_fmt("ERROR: pci_alloc_consistent() FAILED to allocate memory for RISC program! Returning\n")); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 455 | return -ENOMEM; |
| 456 | } |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 457 | /* Clear out memory at address */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 458 | memset(dev->_risc_virt_addr, 0, dev->_audiorisc_size); |
| 459 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 460 | /* For Audio Data buffer allocation */ |
Leonid V. Fedorenchik | 72a52fc | 2011-10-22 01:43:27 -0300 | [diff] [blame^] | 461 | dev->_audiodata_buf_virt_addr = pci_alloc_consistent(dev->pci, |
| 462 | dev->audio_upstream_databuf_size, &data_dma_addr); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 463 | dev->_audiodata_buf_phys_addr = data_dma_addr; |
| 464 | dev->_audiodata_buf_size = dev->audio_upstream_databuf_size; |
| 465 | |
| 466 | if (!dev->_audiodata_buf_virt_addr) { |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 467 | printk(KERN_DEBUG |
Leonid V. Fedorenchik | 81f4c8d | 2011-10-22 01:43:25 -0300 | [diff] [blame] | 468 | pr_fmt("ERROR: pci_alloc_consistent() FAILED to allocate memory for data buffer! Returning\n")); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 469 | return -ENOMEM; |
| 470 | } |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 471 | /* Clear out memory at address */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 472 | memset(dev->_audiodata_buf_virt_addr, 0, dev->_audiodata_buf_size); |
| 473 | |
| 474 | ret = cx25821_openfile_audio(dev, sram_ch); |
| 475 | if (ret < 0) |
| 476 | return ret; |
| 477 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 478 | /* Creating RISC programs */ |
Leonid V. Fedorenchik | 72a52fc | 2011-10-22 01:43:27 -0300 | [diff] [blame^] | 479 | ret = cx25821_risc_buffer_upstream_audio(dev, dev->pci, bpl, |
| 480 | dev->_audio_lines_count); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 481 | if (ret < 0) { |
| 482 | printk(KERN_DEBUG |
Leonid V. Fedorenchik | 81f4c8d | 2011-10-22 01:43:25 -0300 | [diff] [blame] | 483 | pr_fmt("ERROR creating audio upstream RISC programs!\n")); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 484 | goto error; |
| 485 | } |
| 486 | |
| 487 | return 0; |
| 488 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 489 | error: |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 490 | return ret; |
| 491 | } |
| 492 | |
| 493 | int cx25821_audio_upstream_irq(struct cx25821_dev *dev, int chan_num, |
| 494 | u32 status) |
| 495 | { |
| 496 | int i = 0; |
| 497 | u32 int_msk_tmp; |
Ruslan Pisarev | e4115bb | 2010-09-27 10:01:36 -0300 | [diff] [blame] | 498 | struct sram_channel *channel = dev->channels[chan_num].sram_channels; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 499 | dma_addr_t risc_phys_jump_addr; |
| 500 | __le32 *rp; |
| 501 | |
| 502 | if (status & FLD_AUD_SRC_RISCI1) { |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 503 | /* Get interrupt_index of the program that interrupted */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 504 | u32 prog_cnt = cx_read(channel->gpcnt); |
| 505 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 506 | /* Since we've identified our IRQ, clear our bits from the |
| 507 | * interrupt mask and interrupt status registers */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 508 | cx_write(channel->int_msk, 0); |
| 509 | cx_write(channel->int_stat, cx_read(channel->int_stat)); |
| 510 | |
| 511 | spin_lock(&dev->slock); |
| 512 | |
| 513 | while (prog_cnt != dev->_last_index_irq) { |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 514 | /* Update _last_index_irq */ |
| 515 | if (dev->_last_index_irq < (NUMBER_OF_PROGRAMS - 1)) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 516 | dev->_last_index_irq++; |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 517 | else |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 518 | dev->_last_index_irq = 0; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 519 | |
| 520 | dev->_audioframe_index = dev->_last_index_irq; |
| 521 | |
| 522 | queue_work(dev->_irq_audio_queues, |
| 523 | &dev->_audio_work_entry); |
| 524 | } |
| 525 | |
| 526 | if (dev->_is_first_audio_frame) { |
| 527 | dev->_is_first_audio_frame = 0; |
| 528 | |
| 529 | if (dev->_risc_virt_start_addr != NULL) { |
| 530 | risc_phys_jump_addr = |
Leonid V. Fedorenchik | 81f4c8d | 2011-10-22 01:43:25 -0300 | [diff] [blame] | 531 | dev->_risc_phys_start_addr + |
| 532 | RISC_SYNC_INSTRUCTION_SIZE + |
| 533 | AUDIO_RISC_DMA_BUF_SIZE; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 534 | |
| 535 | rp = cx25821_risc_field_upstream_audio(dev, |
Leonid V. Fedorenchik | 54082f1 | 2011-09-02 11:55:39 +0800 | [diff] [blame] | 536 | dev->_risc_virt_start_addr + 1, |
| 537 | dev->_audiodata_buf_phys_addr, |
| 538 | AUDIO_LINE_SIZE, FIFO_DISABLE); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 539 | |
| 540 | if (USE_RISC_NOOP_AUDIO) { |
| 541 | for (i = 0; i < NUM_NO_OPS; i++) { |
| 542 | *(rp++) = |
| 543 | cpu_to_le32(RISC_NOOP); |
| 544 | } |
| 545 | } |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 546 | /* Jump to 2nd Audio Frame */ |
Leonid V. Fedorenchik | 1531e88 | 2011-09-02 11:55:38 +0800 | [diff] [blame] | 547 | *(rp++) = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 548 | RISC_CNT_RESET); |
| 549 | *(rp++) = cpu_to_le32(risc_phys_jump_addr); |
| 550 | *(rp++) = cpu_to_le32(0); |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | spin_unlock(&dev->slock); |
| 555 | } else { |
| 556 | if (status & FLD_AUD_SRC_OF) |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 557 | pr_warn("%s(): Audio Received Overflow Error Interrupt!\n", |
| 558 | __func__); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 559 | |
| 560 | if (status & FLD_AUD_SRC_SYNC) |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 561 | pr_warn("%s(): Audio Received Sync Error Interrupt!\n", |
| 562 | __func__); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 563 | |
| 564 | if (status & FLD_AUD_SRC_OPC_ERR) |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 565 | pr_warn("%s(): Audio Received OpCode Error Interrupt!\n", |
| 566 | __func__); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 567 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 568 | /* Read and write back the interrupt status register to clear |
| 569 | * our bits */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 570 | cx_write(channel->int_stat, cx_read(channel->int_stat)); |
| 571 | } |
| 572 | |
| 573 | if (dev->_audiofile_status == END_OF_FILE) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 574 | pr_warn("EOF Channel Audio Framecount = %d\n", |
| 575 | dev->_audioframe_count); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 576 | return -1; |
| 577 | } |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 578 | /* ElSE, set the interrupt mask register, re-enable irq. */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 579 | int_msk_tmp = cx_read(channel->int_msk); |
| 580 | cx_write(channel->int_msk, int_msk_tmp |= _intr_msk); |
| 581 | |
| 582 | return 0; |
| 583 | } |
| 584 | |
| 585 | static irqreturn_t cx25821_upstream_irq_audio(int irq, void *dev_id) |
| 586 | { |
| 587 | struct cx25821_dev *dev = dev_id; |
| 588 | u32 msk_stat, audio_status; |
| 589 | int handled = 0; |
| 590 | struct sram_channel *sram_ch; |
| 591 | |
| 592 | if (!dev) |
| 593 | return -1; |
| 594 | |
Leonid V. Fedorenchik | 6100c57 | 2011-09-02 11:55:30 +0800 | [diff] [blame] | 595 | sram_ch = dev->channels[dev->_audio_upstream_channel].sram_channels; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 596 | |
| 597 | msk_stat = cx_read(sram_ch->int_mstat); |
| 598 | audio_status = cx_read(sram_ch->int_stat); |
| 599 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 600 | /* Only deal with our interrupt */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 601 | if (audio_status) { |
Leonid V. Fedorenchik | 1531e88 | 2011-09-02 11:55:38 +0800 | [diff] [blame] | 602 | handled = cx25821_audio_upstream_irq(dev, |
| 603 | dev->_audio_upstream_channel, audio_status); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 604 | } |
| 605 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 606 | if (handled < 0) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 607 | cx25821_stop_upstream_audio(dev); |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 608 | else |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 609 | handled += handled; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 610 | |
| 611 | return IRQ_RETVAL(handled); |
| 612 | } |
| 613 | |
| 614 | static void cx25821_wait_fifo_enable(struct cx25821_dev *dev, |
| 615 | struct sram_channel *sram_ch) |
| 616 | { |
| 617 | int count = 0; |
| 618 | u32 tmp; |
| 619 | |
| 620 | do { |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 621 | /* Wait 10 microsecond before checking to see if the FIFO is |
| 622 | * turned ON. */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 623 | udelay(10); |
| 624 | |
| 625 | tmp = cx_read(sram_ch->dma_ctl); |
| 626 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 627 | /* 10 millisecond timeout */ |
| 628 | if (count++ > 1000) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 629 | pr_err("ERROR: %s() fifo is NOT turned on. Timeout!\n", |
Leonid V. Fedorenchik | 81f4c8d | 2011-10-22 01:43:25 -0300 | [diff] [blame] | 630 | __func__); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 631 | return; |
| 632 | } |
| 633 | |
| 634 | } while (!(tmp & sram_ch->fld_aud_fifo_en)); |
| 635 | |
| 636 | } |
| 637 | |
| 638 | int cx25821_start_audio_dma_upstream(struct cx25821_dev *dev, |
| 639 | struct sram_channel *sram_ch) |
| 640 | { |
| 641 | u32 tmp = 0; |
| 642 | int err = 0; |
| 643 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 644 | /* Set the physical start address of the RISC program in the initial |
| 645 | * program counter(IPC) member of the CMDS. */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 646 | cx_write(sram_ch->cmds_start + 0, dev->_risc_phys_addr); |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 647 | /* Risc IPC High 64 bits 63-32 */ |
| 648 | cx_write(sram_ch->cmds_start + 4, 0); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 649 | |
| 650 | /* reset counter */ |
| 651 | cx_write(sram_ch->gpcnt_ctl, 3); |
| 652 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 653 | /* Set the line length (It looks like we do not need to set the |
| 654 | * line length) */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 655 | cx_write(sram_ch->aud_length, AUDIO_LINE_SIZE & FLD_AUD_DST_LN_LNGTH); |
| 656 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 657 | /* Set the input mode to 16-bit */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 658 | tmp = cx_read(sram_ch->aud_cfg); |
Leonid V. Fedorenchik | 72a52fc | 2011-10-22 01:43:27 -0300 | [diff] [blame^] | 659 | tmp |= FLD_AUD_SRC_ENABLE | FLD_AUD_DST_PK_MODE | FLD_AUD_CLK_ENABLE | |
| 660 | FLD_AUD_MASTER_MODE | FLD_AUD_CLK_SELECT_PLL_D | |
| 661 | FLD_AUD_SONY_MODE; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 662 | cx_write(sram_ch->aud_cfg, tmp); |
| 663 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 664 | /* Read and write back the interrupt status register to clear it */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 665 | tmp = cx_read(sram_ch->int_stat); |
| 666 | cx_write(sram_ch->int_stat, tmp); |
| 667 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 668 | /* Clear our bits from the interrupt status register. */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 669 | cx_write(sram_ch->int_stat, _intr_msk); |
| 670 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 671 | /* Set the interrupt mask register, enable irq. */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 672 | cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1 << sram_ch->irq_bit)); |
| 673 | tmp = cx_read(sram_ch->int_msk); |
| 674 | cx_write(sram_ch->int_msk, tmp |= _intr_msk); |
| 675 | |
Leonid V. Fedorenchik | 72a52fc | 2011-10-22 01:43:27 -0300 | [diff] [blame^] | 676 | err = request_irq(dev->pci->irq, cx25821_upstream_irq_audio, |
Yong Zhang | 18e9351 | 2011-09-07 16:10:22 +0800 | [diff] [blame] | 677 | IRQF_SHARED, dev->name, dev); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 678 | if (err < 0) { |
Leonid V. Fedorenchik | 72a52fc | 2011-10-22 01:43:27 -0300 | [diff] [blame^] | 679 | pr_err("%s: can't get upstream IRQ %d\n", dev->name, |
| 680 | dev->pci->irq); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 681 | goto fail_irq; |
| 682 | } |
| 683 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 684 | /* Start the DMA engine */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 685 | tmp = cx_read(sram_ch->dma_ctl); |
| 686 | cx_set(sram_ch->dma_ctl, tmp | sram_ch->fld_aud_risc_en); |
| 687 | |
| 688 | dev->_audio_is_running = 1; |
| 689 | dev->_is_first_audio_frame = 1; |
| 690 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 691 | /* The fifo_en bit turns on by the first Risc program */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 692 | cx25821_wait_fifo_enable(dev, sram_ch); |
| 693 | |
| 694 | return 0; |
| 695 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 696 | fail_irq: |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 697 | cx25821_dev_unregister(dev); |
| 698 | return err; |
| 699 | } |
| 700 | |
| 701 | int cx25821_audio_upstream_init(struct cx25821_dev *dev, int channel_select) |
| 702 | { |
| 703 | struct sram_channel *sram_ch; |
| 704 | int retval = 0; |
| 705 | int err = 0; |
| 706 | int str_length = 0; |
| 707 | |
| 708 | if (dev->_audio_is_running) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 709 | pr_warn("Audio Channel is still running so return!\n"); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 710 | return 0; |
| 711 | } |
| 712 | |
Leonid V. Fedorenchik | 6100c57 | 2011-09-02 11:55:30 +0800 | [diff] [blame] | 713 | dev->_audio_upstream_channel = channel_select; |
Ruslan Pisarev | e4115bb | 2010-09-27 10:01:36 -0300 | [diff] [blame] | 714 | sram_ch = dev->channels[channel_select].sram_channels; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 715 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 716 | /* Work queue */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 717 | INIT_WORK(&dev->_audio_work_entry, cx25821_audioups_handler); |
| 718 | dev->_irq_audio_queues = |
| 719 | create_singlethread_workqueue("cx25821_audioworkqueue"); |
| 720 | |
| 721 | if (!dev->_irq_audio_queues) { |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 722 | printk(KERN_DEBUG |
Leonid V. Fedorenchik | 81f4c8d | 2011-10-22 01:43:25 -0300 | [diff] [blame] | 723 | pr_fmt("ERROR: create_singlethread_workqueue() for Audio FAILED!\n")); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 724 | return -ENOMEM; |
| 725 | } |
| 726 | |
| 727 | dev->_last_index_irq = 0; |
| 728 | dev->_audio_is_running = 0; |
| 729 | dev->_audioframe_count = 0; |
| 730 | dev->_audiofile_status = RESET_STATUS; |
| 731 | dev->_audio_lines_count = LINES_PER_AUDIO_BUFFER; |
| 732 | _line_size = AUDIO_LINE_SIZE; |
| 733 | |
| 734 | if (dev->input_audiofilename) { |
| 735 | str_length = strlen(dev->input_audiofilename); |
Julia Lawall | 3241487 | 2010-05-11 20:26:57 +0200 | [diff] [blame] | 736 | dev->_audiofilename = kmalloc(str_length + 1, GFP_KERNEL); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 737 | |
| 738 | if (!dev->_audiofilename) |
| 739 | goto error; |
| 740 | |
| 741 | memcpy(dev->_audiofilename, dev->input_audiofilename, |
| 742 | str_length + 1); |
| 743 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 744 | /* Default if filename is empty string */ |
Ruslan Pisarev | e4115bb | 2010-09-27 10:01:36 -0300 | [diff] [blame] | 745 | if (strcmp(dev->input_audiofilename, "") == 0) |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 746 | dev->_audiofilename = "/root/audioGOOD.wav"; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 747 | } else { |
| 748 | str_length = strlen(_defaultAudioName); |
Julia Lawall | 3241487 | 2010-05-11 20:26:57 +0200 | [diff] [blame] | 749 | dev->_audiofilename = kmalloc(str_length + 1, GFP_KERNEL); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 750 | |
| 751 | if (!dev->_audiofilename) |
| 752 | goto error; |
| 753 | |
| 754 | memcpy(dev->_audiofilename, _defaultAudioName, str_length + 1); |
| 755 | } |
| 756 | |
Leonid V. Fedorenchik | 1531e88 | 2011-09-02 11:55:38 +0800 | [diff] [blame] | 757 | retval = cx25821_sram_channel_setup_upstream_audio(dev, sram_ch, |
| 758 | _line_size, 0); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 759 | |
| 760 | dev->audio_upstream_riscbuf_size = |
Leonid V. Fedorenchik | 81f4c8d | 2011-10-22 01:43:25 -0300 | [diff] [blame] | 761 | AUDIO_RISC_DMA_BUF_SIZE * NUM_AUDIO_PROGS + |
| 762 | RISC_SYNC_INSTRUCTION_SIZE; |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 763 | dev->audio_upstream_databuf_size = AUDIO_DATA_BUF_SZ * NUM_AUDIO_PROGS; |
| 764 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 765 | /* Allocating buffers and prepare RISC program */ |
Leonid V. Fedorenchik | 1531e88 | 2011-09-02 11:55:38 +0800 | [diff] [blame] | 766 | retval = cx25821_audio_upstream_buffer_prepare(dev, sram_ch, |
| 767 | _line_size); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 768 | if (retval < 0) { |
Joe Perches | 36d89f7 | 2010-11-07 17:48:21 -0300 | [diff] [blame] | 769 | pr_err("%s: Failed to set up Audio upstream buffers!\n", |
Leonid V. Fedorenchik | 81f4c8d | 2011-10-22 01:43:25 -0300 | [diff] [blame] | 770 | dev->name); |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 771 | goto error; |
| 772 | } |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 773 | /* Start RISC engine */ |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 774 | cx25821_start_audio_dma_upstream(dev, sram_ch); |
| 775 | |
| 776 | return 0; |
| 777 | |
Mauro Carvalho Chehab | b5f11cc | 2010-05-18 00:51:02 -0300 | [diff] [blame] | 778 | error: |
Mauro Carvalho Chehab | 1a9fc85 | 2009-09-13 11:30:11 -0300 | [diff] [blame] | 779 | cx25821_dev_unregister(dev); |
| 780 | |
| 781 | return err; |
| 782 | } |