Deepa Madiregama | 52a74c0 | 2011-10-28 10:54:43 +0530 | [diff] [blame^] | 1 | /* evrc audio output device |
| 2 | * |
| 3 | * Copyright (C) 2008 Google, Inc. |
| 4 | * Copyright (C) 2008 HTC Corporation |
| 5 | * Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
| 6 | * |
| 7 | * This software is licensed under the terms of the GNU General Public |
| 8 | * License version 2, as published by the Free Software Foundation, and |
| 9 | * may be copied, distributed, and modified under those terms. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | #include "audio_utils_aio.h" |
| 19 | |
| 20 | static void q6_audio_evrc_cb(uint32_t opcode, uint32_t token, |
| 21 | uint32_t *payload, void *priv) |
| 22 | { |
| 23 | struct q6audio_aio *audio = (struct q6audio_aio *)priv; |
| 24 | |
| 25 | pr_debug("%s:opcde = %d token = 0x%x\n", __func__, opcode, token); |
| 26 | switch (opcode) { |
| 27 | case ASM_DATA_EVENT_WRITE_DONE: |
| 28 | case ASM_DATA_EVENT_READ_DONE: |
| 29 | case ASM_DATA_CMDRSP_EOS: |
| 30 | audio_aio_cb(opcode, token, payload, audio); |
| 31 | break; |
| 32 | default: |
| 33 | pr_debug("%s:Unhandled event = 0x%8x\n", __func__, opcode); |
| 34 | break; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | #ifdef CONFIG_DEBUG_FS |
| 39 | static const struct file_operations audio_evrc_debug_fops = { |
| 40 | .read = audio_aio_debug_read, |
| 41 | .open = audio_aio_debug_open, |
| 42 | }; |
| 43 | #endif |
| 44 | |
| 45 | static long audio_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 46 | { |
| 47 | struct q6audio_aio *audio = file->private_data; |
| 48 | int rc = 0; |
| 49 | |
| 50 | switch (cmd) { |
| 51 | case AUDIO_START: { |
| 52 | pr_debug("%s[%p]: AUDIO_START session_id[%d]\n", __func__, |
| 53 | audio, audio->ac->session); |
| 54 | if (audio->feedback == NON_TUNNEL_MODE) { |
| 55 | /* Configure PCM output block */ |
| 56 | rc = q6asm_enc_cfg_blk_pcm(audio->ac, |
| 57 | audio->pcm_cfg.sample_rate, |
| 58 | audio->pcm_cfg.channel_count); |
| 59 | if (rc < 0) { |
| 60 | pr_err("pcm output block config failed\n"); |
| 61 | break; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | rc = audio_aio_enable(audio); |
| 66 | audio->eos_rsp = 0; |
| 67 | audio->eos_flag = 0; |
| 68 | if (!rc) { |
| 69 | audio->enabled = 1; |
| 70 | } else { |
| 71 | audio->enabled = 0; |
| 72 | pr_err("Audio Start procedure failed rc=%d\n", rc); |
| 73 | break; |
| 74 | } |
| 75 | pr_debug("%s: AUDIO_START sessionid[%d]enable[%d]\n", __func__, |
| 76 | audio->ac->session, |
| 77 | audio->enabled); |
| 78 | if (audio->stopped == 1) |
| 79 | audio->stopped = 0; |
| 80 | break; |
| 81 | } |
| 82 | default: |
| 83 | pr_debug("%s[%p]: Calling utils ioctl\n", __func__, audio); |
| 84 | rc = audio->codec_ioctl(file, cmd, arg); |
| 85 | } |
| 86 | return rc; |
| 87 | } |
| 88 | |
| 89 | static int audio_open(struct inode *inode, struct file *file) |
| 90 | { |
| 91 | struct q6audio_aio *audio = NULL; |
| 92 | int rc = 0; |
| 93 | |
| 94 | #ifdef CONFIG_DEBUG_FS |
| 95 | /* 4 bytes represents decoder number, 1 byte for terminate string */ |
| 96 | char name[sizeof "msm_evrc_" + 5]; |
| 97 | #endif |
| 98 | audio = kzalloc(sizeof(struct q6audio_aio), GFP_KERNEL); |
| 99 | |
| 100 | if (audio == NULL) { |
| 101 | pr_err("Could not allocate memory for aac decode driver\n"); |
| 102 | return -ENOMEM; |
| 103 | } |
| 104 | |
| 105 | /* Settings will be re-config at AUDIO_SET_CONFIG, |
| 106 | * but at least we need to have initial config |
| 107 | */ |
| 108 | audio->pcm_cfg.buffer_size = PCM_BUFSZ_MIN; |
| 109 | |
| 110 | audio->ac = q6asm_audio_client_alloc((app_cb) q6_audio_evrc_cb, |
| 111 | (void *)audio); |
| 112 | |
| 113 | if (!audio->ac) { |
| 114 | pr_err("Could not allocate memory for audio client\n"); |
| 115 | kfree(audio); |
| 116 | return -ENOMEM; |
| 117 | } |
| 118 | |
| 119 | /* open in T/NT mode */ |
| 120 | if ((file->f_mode & FMODE_WRITE) && (file->f_mode & FMODE_READ)) { |
| 121 | rc = q6asm_open_read_write(audio->ac, FORMAT_LINEAR_PCM, |
| 122 | FORMAT_EVRC); |
| 123 | if (rc < 0) { |
| 124 | pr_err("NT mode Open failed rc=%d\n", rc); |
| 125 | rc = -ENODEV; |
| 126 | goto fail; |
| 127 | } |
| 128 | audio->feedback = NON_TUNNEL_MODE; |
| 129 | audio->buf_cfg.frames_per_buf = 0x01; |
| 130 | audio->buf_cfg.meta_info_enable = 0x01; |
| 131 | } else if ((file->f_mode & FMODE_WRITE) && |
| 132 | !(file->f_mode & FMODE_READ)) { |
| 133 | rc = q6asm_open_write(audio->ac, FORMAT_EVRC); |
| 134 | if (rc < 0) { |
| 135 | pr_err("T mode Open failed rc=%d\n", rc); |
| 136 | rc = -ENODEV; |
| 137 | goto fail; |
| 138 | } |
| 139 | audio->feedback = TUNNEL_MODE; |
| 140 | audio->buf_cfg.meta_info_enable = 0x00; |
| 141 | } else { |
| 142 | pr_err("Not supported mode\n"); |
| 143 | rc = -EACCES; |
| 144 | goto fail; |
| 145 | } |
| 146 | rc = audio_aio_open(audio, file); |
| 147 | |
| 148 | #ifdef CONFIG_DEBUG_FS |
| 149 | snprintf(name, sizeof name, "msm_evrc_%04x", audio->ac->session); |
| 150 | audio->dentry = debugfs_create_file(name, S_IFREG | S_IRUGO, |
| 151 | NULL, (void *)audio, |
| 152 | &audio_evrc_debug_fops); |
| 153 | |
| 154 | if (IS_ERR(audio->dentry)) |
| 155 | pr_debug("debugfs_create_file failed\n"); |
| 156 | #endif |
| 157 | pr_info("%s:dec success mode[%d]session[%d]\n", __func__, |
| 158 | audio->feedback, |
| 159 | audio->ac->session); |
| 160 | return rc; |
| 161 | fail: |
| 162 | q6asm_audio_client_free(audio->ac); |
| 163 | kfree(audio); |
| 164 | return rc; |
| 165 | } |
| 166 | |
| 167 | static const struct file_operations audio_evrc_fops = { |
| 168 | .owner = THIS_MODULE, |
| 169 | .open = audio_open, |
| 170 | .release = audio_aio_release, |
| 171 | .unlocked_ioctl = audio_ioctl, |
| 172 | .fsync = audio_aio_fsync, |
| 173 | }; |
| 174 | |
| 175 | struct miscdevice audio_evrc_misc = { |
| 176 | .minor = MISC_DYNAMIC_MINOR, |
| 177 | .name = "msm_evrc", |
| 178 | .fops = &audio_evrc_fops, |
| 179 | }; |
| 180 | |
| 181 | static int __init audio_evrc_init(void) |
| 182 | { |
| 183 | return misc_register(&audio_evrc_misc); |
| 184 | } |
| 185 | |
| 186 | device_initcall(audio_evrc_init); |