blob: 4435f3e71c8880047b3b3d0cf48da6b326946b74 [file] [log] [blame]
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301/* mp3 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
20static struct miscdevice audio_mp3_misc;
21static struct ws_mgr audio_mp3_ws_mgr;
22
23#ifdef CONFIG_DEBUG_FS
24static const struct file_operations audio_mp3_debug_fops = {
25 .read = audio_aio_debug_read,
26 .open = audio_aio_debug_open,
27};
28#endif
29
30static long audio_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31{
32 struct q6audio_aio *audio = file->private_data;
33 int rc = 0;
34
35 switch (cmd) {
36 case AUDIO_START: {
37 pr_debug("%s[%pK]: AUDIO_START session_id[%d]\n", __func__,
38 audio, audio->ac->session);
39 if (audio->feedback == NON_TUNNEL_MODE) {
40 /* Configure PCM output block */
41 rc = q6asm_enc_cfg_blk_pcm(audio->ac,
42 audio->pcm_cfg.sample_rate,
43 audio->pcm_cfg.channel_count);
44 if (rc < 0) {
45 pr_err("pcm output block config failed\n");
46 break;
47 }
48 }
49
50 rc = audio_aio_enable(audio);
51 audio->eos_rsp = 0;
52 audio->eos_flag = 0;
53 if (!rc) {
54 rc = enable_volume_ramp(audio);
55 if (rc < 0) {
56 pr_err("%s: Failed to enable volume ramp\n",
57 __func__);
58 }
59 audio->enabled = 1;
60 } else {
61 audio->enabled = 0;
62 pr_err("Audio Start procedure failed rc=%d\n", rc);
63 break;
64 }
65 pr_info("%s: AUDIO_START sessionid[%d]enable[%d]\n", __func__,
66 audio->ac->session,
67 audio->enabled);
68 if (audio->stopped == 1)
69 audio->stopped = 0;
70 break;
71 }
72 default:
73 pr_debug("%s[%pK]: Calling utils ioctl\n", __func__, audio);
74 rc = audio->codec_ioctl(file, cmd, arg);
75 }
76 return rc;
77}
78
79static int audio_open(struct inode *inode, struct file *file)
80{
81 struct q6audio_aio *audio = NULL;
82 int rc = 0;
83
84#ifdef CONFIG_DEBUG_FS
85 /* 4 bytes represents decoder number, 1 byte for terminate string */
86 char name[sizeof "msm_mp3_" + 5];
87#endif
88 audio = kzalloc(sizeof(struct q6audio_aio), GFP_KERNEL);
89
90 if (audio == NULL)
91 return -ENOMEM;
92
93 audio->pcm_cfg.buffer_size = PCM_BUFSZ_MIN;
94 audio->miscdevice = &audio_mp3_misc;
95 audio->wakelock_voted = false;
96 audio->audio_ws_mgr = &audio_mp3_ws_mgr;
97
98 audio->ac = q6asm_audio_client_alloc((app_cb) q6_audio_cb,
99 (void *)audio);
100
101 if (!audio->ac) {
102 pr_err("Could not allocate memory for audio client\n");
103 kfree(audio);
104 return -ENOMEM;
105 }
106 rc = audio_aio_open(audio, file);
107 if (rc < 0) {
108 pr_err("%s: audio_aio_open rc=%d\n",
109 __func__, rc);
110 goto fail;
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_MP3);
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 /* open MP3 decoder, expected frames is always 1
124 * audio->buf_cfg.frames_per_buf = 0x01;
125 */
126 audio->buf_cfg.meta_info_enable = 0x01;
127 } else if ((file->f_mode & FMODE_WRITE) &&
128 !(file->f_mode & FMODE_READ)) {
129 rc = q6asm_open_write(audio->ac, FORMAT_MP3);
130 if (rc < 0) {
131 pr_err("T mode Open failed rc=%d\n", rc);
132 rc = -ENODEV;
133 goto fail;
134 }
135 audio->feedback = TUNNEL_MODE;
136 audio->buf_cfg.meta_info_enable = 0x00;
137 } else {
138 pr_err("Not supported mode\n");
139 rc = -EACCES;
140 goto fail;
141 }
142
143#ifdef CONFIG_DEBUG_FS
144 snprintf(name, sizeof(name), "msm_mp3_%04x", audio->ac->session);
145 audio->dentry = debugfs_create_file(name, S_IFREG | 0444,
146 NULL, (void *)audio,
147 &audio_mp3_debug_fops);
148
149 if (IS_ERR(audio->dentry))
150 pr_debug("debugfs_create_file failed\n");
151#endif
152 pr_info("%s:mp3dec success mode[%d]session[%d]\n", __func__,
153 audio->feedback,
154 audio->ac->session);
155 return rc;
156fail:
157 q6asm_audio_client_free(audio->ac);
158 kfree(audio);
159 return rc;
160}
161
162static const struct file_operations audio_mp3_fops = {
163 .owner = THIS_MODULE,
164 .open = audio_open,
165 .release = audio_aio_release,
166 .unlocked_ioctl = audio_ioctl,
167 .fsync = audio_aio_fsync,
168};
169
170static struct miscdevice audio_mp3_misc = {
171 .minor = MISC_DYNAMIC_MINOR,
172 .name = "msm_mp3",
173 .fops = &audio_mp3_fops,
174};
175
Laxminath Kasam8b1366a2017-10-05 01:44:16 +0530176int __init audio_mp3_init(void)
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530177{
178 int ret = misc_register(&audio_mp3_misc);
179
180 if (ret == 0)
181 device_init_wakeup(audio_mp3_misc.this_device, true);
182 audio_mp3_ws_mgr.ref_cnt = 0;
183 mutex_init(&audio_mp3_ws_mgr.ws_lock);
184
185 return ret;
186}
187
Asish Bhattacharya5faacb32017-12-04 17:23:15 +0530188void audio_mp3_exit(void)
Laxminath Kasam8b1366a2017-10-05 01:44:16 +0530189{
190 mutex_destroy(&audio_mp3_ws_mgr.ws_lock);
191 misc_deregister(&audio_mp3_misc);
192}