blob: 3498e6927a292126667d4a0119f1bcad3b3e000c [file] [log] [blame]
Deepa Madiregama52a74c02011-10-28 10:54:43 +05301/* evrc audio output device
2 *
3 * Copyright (C) 2008 Google, Inc.
4 * Copyright (C) 2008 HTC Corporation
Kuirong Wang86d5e7a2013-02-12 18:45:49 -08005 * Copyright (c) 2011-2013, 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
Deepa Madiregama52a74c02011-10-28 10:54:43 +053020
Deepa Madiregama52a74c02011-10-28 10:54:43 +053021
22#ifdef CONFIG_DEBUG_FS
23static const struct file_operations audio_evrc_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_evrc_" + 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->pcm_cfg.buffer_size = PCM_BUFSZ_MIN;
93
Harmandeep Singhc35fa07d2012-05-31 07:08:59 -070094 audio->ac = q6asm_audio_client_alloc((app_cb) q6_audio_cb,
Deepa Madiregama52a74c02011-10-28 10:54:43 +053095 (void *)audio);
96
97 if (!audio->ac) {
98 pr_err("Could not allocate memory for audio client\n");
99 kfree(audio);
100 return -ENOMEM;
101 }
102
103 /* open in T/NT mode */
104 if ((file->f_mode & FMODE_WRITE) && (file->f_mode & FMODE_READ)) {
105 rc = q6asm_open_read_write(audio->ac, FORMAT_LINEAR_PCM,
106 FORMAT_EVRC);
107 if (rc < 0) {
108 pr_err("NT mode Open failed rc=%d\n", rc);
109 rc = -ENODEV;
110 goto fail;
111 }
112 audio->feedback = NON_TUNNEL_MODE;
113 audio->buf_cfg.frames_per_buf = 0x01;
114 audio->buf_cfg.meta_info_enable = 0x01;
115 } else if ((file->f_mode & FMODE_WRITE) &&
116 !(file->f_mode & FMODE_READ)) {
117 rc = q6asm_open_write(audio->ac, FORMAT_EVRC);
118 if (rc < 0) {
119 pr_err("T mode Open failed rc=%d\n", rc);
120 rc = -ENODEV;
121 goto fail;
122 }
123 audio->feedback = TUNNEL_MODE;
124 audio->buf_cfg.meta_info_enable = 0x00;
125 } else {
126 pr_err("Not supported mode\n");
127 rc = -EACCES;
128 goto fail;
129 }
130 rc = audio_aio_open(audio, file);
Kuirong Wang86d5e7a2013-02-12 18:45:49 -0800131 if (rc < 0) {
132 pr_err("audio_aio_open rc=%d\n", rc);
133 goto fail;
134 }
Deepa Madiregama52a74c02011-10-28 10:54:43 +0530135
136#ifdef CONFIG_DEBUG_FS
137 snprintf(name, sizeof name, "msm_evrc_%04x", audio->ac->session);
138 audio->dentry = debugfs_create_file(name, S_IFREG | S_IRUGO,
139 NULL, (void *)audio,
140 &audio_evrc_debug_fops);
141
142 if (IS_ERR(audio->dentry))
143 pr_debug("debugfs_create_file failed\n");
144#endif
145 pr_info("%s:dec success mode[%d]session[%d]\n", __func__,
146 audio->feedback,
147 audio->ac->session);
148 return rc;
149fail:
150 q6asm_audio_client_free(audio->ac);
151 kfree(audio);
152 return rc;
153}
154
155static const struct file_operations audio_evrc_fops = {
156 .owner = THIS_MODULE,
157 .open = audio_open,
158 .release = audio_aio_release,
159 .unlocked_ioctl = audio_ioctl,
160 .fsync = audio_aio_fsync,
161};
162
163struct miscdevice audio_evrc_misc = {
164 .minor = MISC_DYNAMIC_MINOR,
165 .name = "msm_evrc",
166 .fops = &audio_evrc_fops,
167};
168
169static int __init audio_evrc_init(void)
170{
171 return misc_register(&audio_evrc_misc);
172}
173
174device_initcall(audio_evrc_init);