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