Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1 | /* qcelp(v13k) audio output device |
| 2 | * |
| 3 | * Copyright (C) 2008 Google, Inc. |
| 4 | * Copyright (C) 2008 HTC Corporation |
| 5 | * Copyright (c) 2011-2017, The Linux Foundation. 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 | #define FRAME_SIZE_DEC_QCELP ((32) + sizeof(struct dec_meta_in)) |
| 21 | |
| 22 | static struct miscdevice audio_qcelp_misc; |
| 23 | static struct ws_mgr audio_qcelp_ws_mgr; |
| 24 | |
| 25 | #ifdef CONFIG_DEBUG_FS |
| 26 | static const struct file_operations audio_qcelp_debug_fops = { |
| 27 | .read = audio_aio_debug_read, |
| 28 | .open = audio_aio_debug_open, |
| 29 | }; |
| 30 | #endif |
| 31 | |
| 32 | static long audio_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 33 | { |
| 34 | struct q6audio_aio *audio = file->private_data; |
| 35 | int rc = 0; |
| 36 | |
| 37 | switch (cmd) { |
| 38 | case AUDIO_START: { |
| 39 | pr_debug("%s[%pK]: AUDIO_START session_id[%d]\n", __func__, |
| 40 | audio, audio->ac->session); |
| 41 | if (audio->feedback == NON_TUNNEL_MODE) { |
| 42 | /* Configure PCM output block */ |
| 43 | rc = q6asm_enc_cfg_blk_pcm(audio->ac, |
| 44 | audio->pcm_cfg.sample_rate, |
| 45 | audio->pcm_cfg.channel_count); |
| 46 | if (rc < 0) { |
| 47 | pr_err("pcm output block config failed\n"); |
| 48 | break; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | rc = audio_aio_enable(audio); |
| 53 | audio->eos_rsp = 0; |
| 54 | audio->eos_flag = 0; |
| 55 | if (!rc) { |
| 56 | audio->enabled = 1; |
| 57 | } else { |
| 58 | audio->enabled = 0; |
| 59 | pr_err("Audio Start procedure failed rc=%d\n", rc); |
| 60 | break; |
| 61 | } |
| 62 | pr_debug("%s: AUDIO_START sessionid[%d]enable[%d]\n", __func__, |
| 63 | audio->ac->session, |
| 64 | audio->enabled); |
| 65 | if (audio->stopped == 1) |
| 66 | audio->stopped = 0; |
| 67 | break; |
| 68 | } |
| 69 | default: |
| 70 | pr_debug("%s[%pK]: Calling utils ioctl\n", __func__, audio); |
| 71 | rc = audio->codec_ioctl(file, cmd, arg); |
| 72 | } |
| 73 | return rc; |
| 74 | } |
| 75 | |
| 76 | static int audio_open(struct inode *inode, struct file *file) |
| 77 | { |
| 78 | struct q6audio_aio *audio = NULL; |
| 79 | int rc = 0; |
| 80 | |
| 81 | #ifdef CONFIG_DEBUG_FS |
| 82 | /* 4 bytes represents decoder number, 1 byte for terminate string */ |
| 83 | char name[sizeof "msm_qcelp_" + 5]; |
| 84 | #endif |
| 85 | audio = kzalloc(sizeof(struct q6audio_aio), GFP_KERNEL); |
| 86 | |
| 87 | if (audio == NULL) |
| 88 | return -ENOMEM; |
| 89 | |
| 90 | /* Settings will be re-config at AUDIO_SET_CONFIG, |
| 91 | * but at least we need to have initial config |
| 92 | */ |
| 93 | audio->str_cfg.buffer_size = FRAME_SIZE_DEC_QCELP; |
| 94 | audio->str_cfg.buffer_count = FRAME_NUM; |
| 95 | audio->pcm_cfg.buffer_size = PCM_BUFSZ_MIN; |
| 96 | audio->pcm_cfg.buffer_count = PCM_BUF_COUNT; |
| 97 | audio->pcm_cfg.sample_rate = 8000; |
| 98 | audio->pcm_cfg.channel_count = 1; |
| 99 | audio->miscdevice = &audio_qcelp_misc; |
| 100 | audio->wakelock_voted = false; |
| 101 | audio->audio_ws_mgr = &audio_qcelp_ws_mgr; |
| 102 | |
| 103 | audio->ac = q6asm_audio_client_alloc((app_cb) q6_audio_cb, |
| 104 | (void *)audio); |
| 105 | |
| 106 | if (!audio->ac) { |
| 107 | pr_err("Could not allocate memory for audio client\n"); |
| 108 | kfree(audio); |
| 109 | return -ENOMEM; |
| 110 | } |
| 111 | rc = audio_aio_open(audio, file); |
| 112 | if (rc < 0) { |
| 113 | pr_err("%s: audio_aio_open rc=%d\n", |
| 114 | __func__, rc); |
| 115 | goto fail; |
| 116 | } |
| 117 | |
| 118 | /* open in T/NT mode */ |
| 119 | if ((file->f_mode & FMODE_WRITE) && (file->f_mode & FMODE_READ)) { |
| 120 | rc = q6asm_open_read_write(audio->ac, FORMAT_LINEAR_PCM, |
| 121 | FORMAT_V13K); |
| 122 | if (rc < 0) { |
| 123 | pr_err("NT mode Open failed rc=%d\n", rc); |
| 124 | rc = -ENODEV; |
| 125 | goto fail; |
| 126 | } |
| 127 | audio->feedback = NON_TUNNEL_MODE; |
| 128 | audio->buf_cfg.frames_per_buf = 0x01; |
| 129 | audio->buf_cfg.meta_info_enable = 0x01; |
| 130 | } else if ((file->f_mode & FMODE_WRITE) && |
| 131 | !(file->f_mode & FMODE_READ)) { |
| 132 | rc = q6asm_open_write(audio->ac, FORMAT_V13K); |
| 133 | if (rc < 0) { |
| 134 | pr_err("T mode Open failed rc=%d\n", rc); |
| 135 | rc = -ENODEV; |
| 136 | goto fail; |
| 137 | } |
| 138 | audio->feedback = TUNNEL_MODE; |
| 139 | audio->buf_cfg.meta_info_enable = 0x00; |
| 140 | } else { |
| 141 | pr_err("Not supported mode\n"); |
| 142 | rc = -EACCES; |
| 143 | goto fail; |
| 144 | } |
| 145 | |
| 146 | #ifdef CONFIG_DEBUG_FS |
| 147 | snprintf(name, sizeof(name), "msm_qcelp_%04x", audio->ac->session); |
| 148 | audio->dentry = debugfs_create_file(name, S_IFREG | 0444, |
| 149 | NULL, (void *)audio, |
| 150 | &audio_qcelp_debug_fops); |
| 151 | |
| 152 | if (IS_ERR(audio->dentry)) |
| 153 | pr_debug("debugfs_create_file failed\n"); |
| 154 | #endif |
| 155 | pr_info("%s:dec success mode[%d]session[%d]\n", __func__, |
| 156 | audio->feedback, |
| 157 | audio->ac->session); |
| 158 | return 0; |
| 159 | fail: |
| 160 | q6asm_audio_client_free(audio->ac); |
| 161 | kfree(audio); |
| 162 | return rc; |
| 163 | } |
| 164 | |
| 165 | static const struct file_operations audio_qcelp_fops = { |
| 166 | .owner = THIS_MODULE, |
| 167 | .open = audio_open, |
| 168 | .release = audio_aio_release, |
| 169 | .unlocked_ioctl = audio_ioctl, |
| 170 | .fsync = audio_aio_fsync, |
| 171 | }; |
| 172 | |
| 173 | static struct miscdevice audio_qcelp_misc = { |
| 174 | .minor = MISC_DYNAMIC_MINOR, |
| 175 | .name = "msm_qcelp", |
| 176 | .fops = &audio_qcelp_fops, |
| 177 | }; |
| 178 | |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 179 | int audio_qcelp_init(void) |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 180 | { |
| 181 | int ret = misc_register(&audio_qcelp_misc); |
| 182 | |
| 183 | if (ret == 0) |
| 184 | device_init_wakeup(audio_qcelp_misc.this_device, true); |
| 185 | audio_qcelp_ws_mgr.ref_cnt = 0; |
| 186 | mutex_init(&audio_qcelp_ws_mgr.ws_lock); |
| 187 | |
| 188 | return ret; |
| 189 | } |
| 190 | |
Asish Bhattacharya | 5faacb3 | 2017-12-04 17:23:15 +0530 | [diff] [blame] | 191 | void audio_qcelp_exit(void) |
Laxminath Kasam | 8b1366a | 2017-10-05 01:44:16 +0530 | [diff] [blame] | 192 | { |
| 193 | mutex_destroy(&audio_qcelp_ws_mgr.ws_lock); |
| 194 | misc_deregister(&audio_qcelp_misc); |
| 195 | } |