Deepa Madiregama | 52a74c0 | 2011-10-28 10:54:43 +0530 | [diff] [blame] | 1 | /* amrnb 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 | #include "audio_utils_aio.h" |
| 18 | |
| 19 | static void q6_audio_amrnb_cb(uint32_t opcode, uint32_t token, |
| 20 | uint32_t *payload, void *priv) |
| 21 | { |
| 22 | struct q6audio_aio *audio = (struct q6audio_aio *)priv; |
| 23 | |
| 24 | pr_debug("%s:opcde = %d token = 0x%x\n", __func__, opcode, token); |
| 25 | switch (opcode) { |
| 26 | case ASM_DATA_EVENT_WRITE_DONE: |
| 27 | case ASM_DATA_EVENT_READ_DONE: |
| 28 | case ASM_DATA_CMDRSP_EOS: |
| 29 | audio_aio_cb(opcode, token, payload, audio); |
| 30 | break; |
| 31 | default: |
| 32 | pr_debug("%s:Unhandled event = 0x%8x\n", __func__, opcode); |
| 33 | break; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | #ifdef CONFIG_DEBUG_FS |
| 38 | static const struct file_operations audio_amrnb_debug_fops = { |
| 39 | .read = audio_aio_debug_read, |
| 40 | .open = audio_aio_debug_open, |
| 41 | }; |
| 42 | #endif |
| 43 | |
| 44 | static long audio_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 45 | { |
| 46 | struct q6audio_aio *audio = file->private_data; |
| 47 | int rc = 0; |
| 48 | |
| 49 | switch (cmd) { |
| 50 | case AUDIO_START: { |
| 51 | pr_debug("%s[%p]: AUDIO_START session_id[%d]\n", __func__, |
| 52 | audio, audio->ac->session); |
| 53 | if (audio->feedback == NON_TUNNEL_MODE) { |
| 54 | /* Configure PCM output block */ |
| 55 | rc = q6asm_enc_cfg_blk_pcm(audio->ac, |
| 56 | audio->pcm_cfg.sample_rate, |
| 57 | audio->pcm_cfg.channel_count); |
| 58 | if (rc < 0) { |
| 59 | pr_err("pcm output block config failed\n"); |
| 60 | break; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | rc = audio_aio_enable(audio); |
| 65 | audio->eos_rsp = 0; |
| 66 | audio->eos_flag = 0; |
| 67 | if (!rc) { |
| 68 | audio->enabled = 1; |
| 69 | } else { |
| 70 | audio->enabled = 0; |
| 71 | pr_err("Audio Start procedure failed rc=%d\n", rc); |
| 72 | break; |
| 73 | } |
| 74 | pr_debug("AUDIO_START success enable[%d]\n", audio->enabled); |
| 75 | if (audio->stopped == 1) |
| 76 | audio->stopped = 0; |
| 77 | break; |
| 78 | } |
| 79 | default: |
| 80 | pr_debug("%s[%p]: Calling utils ioctl\n", __func__, audio); |
| 81 | rc = audio->codec_ioctl(file, cmd, arg); |
| 82 | } |
| 83 | return rc; |
| 84 | } |
| 85 | |
| 86 | static int audio_open(struct inode *inode, struct file *file) |
| 87 | { |
| 88 | struct q6audio_aio *audio = NULL; |
| 89 | int rc = 0; |
| 90 | |
| 91 | #ifdef CONFIG_DEBUG_FS |
| 92 | /* 4 bytes represents decoder number, 1 byte for terminate string */ |
| 93 | char name[sizeof "msm_amrnb_" + 5]; |
| 94 | #endif |
| 95 | audio = kzalloc(sizeof(struct q6audio_aio), GFP_KERNEL); |
| 96 | |
| 97 | if (audio == NULL) { |
| 98 | pr_err("Could not allocate memory for wma decode driver\n"); |
| 99 | return -ENOMEM; |
| 100 | } |
| 101 | |
| 102 | audio->pcm_cfg.buffer_size = PCM_BUFSZ_MIN; |
| 103 | |
| 104 | audio->ac = q6asm_audio_client_alloc((app_cb) q6_audio_amrnb_cb, |
| 105 | (void *)audio); |
| 106 | |
| 107 | if (!audio->ac) { |
| 108 | pr_err("Could not allocate memory for audio client\n"); |
| 109 | kfree(audio); |
| 110 | return -ENOMEM; |
| 111 | } |
| 112 | |
| 113 | /* open in T/NT mode */ |
| 114 | if ((file->f_mode & FMODE_WRITE) && (file->f_mode & FMODE_READ)) { |
| 115 | rc = q6asm_open_read_write(audio->ac, FORMAT_LINEAR_PCM, |
| 116 | FORMAT_AMRNB); |
| 117 | if (rc < 0) { |
| 118 | pr_err("NT mode Open failed rc=%d\n", rc); |
| 119 | rc = -ENODEV; |
| 120 | goto fail; |
| 121 | } |
| 122 | audio->feedback = NON_TUNNEL_MODE; |
| 123 | audio->buf_cfg.frames_per_buf = 0x01; |
| 124 | audio->buf_cfg.meta_info_enable = 0x01; |
| 125 | } else if ((file->f_mode & FMODE_WRITE) && |
| 126 | !(file->f_mode & FMODE_READ)) { |
| 127 | rc = q6asm_open_write(audio->ac, FORMAT_AMRNB); |
| 128 | if (rc < 0) { |
| 129 | pr_err("T mode Open failed rc=%d\n", rc); |
| 130 | rc = -ENODEV; |
| 131 | goto fail; |
| 132 | } |
| 133 | audio->feedback = TUNNEL_MODE; |
| 134 | audio->buf_cfg.meta_info_enable = 0x00; |
| 135 | } else { |
| 136 | pr_err("Not supported mode\n"); |
| 137 | rc = -EACCES; |
| 138 | goto fail; |
| 139 | } |
| 140 | rc = audio_aio_open(audio, file); |
| 141 | |
| 142 | #ifdef CONFIG_DEBUG_FS |
| 143 | snprintf(name, sizeof name, "msm_amrnb_%04x", audio->ac->session); |
| 144 | audio->dentry = debugfs_create_file(name, S_IFREG | S_IRUGO, |
| 145 | NULL, (void *)audio, |
| 146 | &audio_amrnb_debug_fops); |
| 147 | |
| 148 | if (IS_ERR(audio->dentry)) |
| 149 | pr_debug("debugfs_create_file failed\n"); |
| 150 | #endif |
| 151 | pr_info("%s:amrnb decoder open success, session_id = %d\n", __func__, |
| 152 | audio->ac->session); |
| 153 | return rc; |
| 154 | fail: |
| 155 | q6asm_audio_client_free(audio->ac); |
| 156 | kfree(audio); |
| 157 | return rc; |
| 158 | } |
| 159 | |
| 160 | static const struct file_operations audio_amrnb_fops = { |
| 161 | .owner = THIS_MODULE, |
| 162 | .open = audio_open, |
| 163 | .release = audio_aio_release, |
| 164 | .unlocked_ioctl = audio_ioctl, |
| 165 | .fsync = audio_aio_fsync, |
| 166 | }; |
| 167 | |
| 168 | struct miscdevice audio_amrnb_misc = { |
| 169 | .minor = MISC_DYNAMIC_MINOR, |
| 170 | .name = "msm_amrnb", |
| 171 | .fops = &audio_amrnb_fops, |
| 172 | }; |
| 173 | |
| 174 | static int __init audio_amrnb_init(void) |
| 175 | { |
| 176 | return misc_register(&audio_amrnb_misc); |
| 177 | } |
| 178 | |
| 179 | device_initcall(audio_amrnb_init); |