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