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