blob: 6cddc9cacf706421e8ccccbce5c7936593d0bf94 [file] [log] [blame]
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +05301/* evrc 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_evrc_misc;
21static struct ws_mgr audio_evrc_ws_mgr;
22
23#ifdef CONFIG_DEBUG_FS
24static const struct file_operations audio_evrc_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 audio->enabled = 1;
55 } else {
56 audio->enabled = 0;
57 pr_err("Audio Start procedure failed rc=%d\n", rc);
58 break;
59 }
60 pr_debug("%s: AUDIO_START sessionid[%d]enable[%d]\n", __func__,
61 audio->ac->session,
62 audio->enabled);
63 if (audio->stopped == 1)
64 audio->stopped = 0;
65 break;
66 }
67 default:
68 pr_debug("%s[%pK]: Calling utils ioctl\n", __func__, audio);
69 rc = audio->codec_ioctl(file, cmd, arg);
70 }
71 return rc;
72}
73
74static int audio_open(struct inode *inode, struct file *file)
75{
76 struct q6audio_aio *audio = NULL;
77 int rc = 0;
78
79#ifdef CONFIG_DEBUG_FS
80 /* 4 bytes represents decoder number, 1 byte for terminate string */
81 char name[sizeof "msm_evrc_" + 5];
82#endif
83 audio = kzalloc(sizeof(struct q6audio_aio), GFP_KERNEL);
84
85 if (audio == NULL)
86 return -ENOMEM;
87
88 /* Settings will be re-config at AUDIO_SET_CONFIG,
89 * but at least we need to have initial config
90 */
91 audio->pcm_cfg.buffer_size = PCM_BUFSZ_MIN;
92 audio->miscdevice = &audio_evrc_misc;
93 audio->wakelock_voted = false;
94 audio->audio_ws_mgr = &audio_evrc_ws_mgr;
95
96 audio->ac = q6asm_audio_client_alloc((app_cb) q6_audio_cb,
97 (void *)audio);
98
99 if (!audio->ac) {
100 pr_err("Could not allocate memory for audio client\n");
101 kfree(audio);
102 return -ENOMEM;
103 }
104 rc = audio_aio_open(audio, file);
105 if (rc < 0) {
106 pr_err("%s: audio_aio_open rc=%d\n",
107 __func__, rc);
108 goto fail;
109 }
110
111 /* open in T/NT mode */
112 if ((file->f_mode & FMODE_WRITE) && (file->f_mode & FMODE_READ)) {
113 rc = q6asm_open_read_write(audio->ac, FORMAT_LINEAR_PCM,
114 FORMAT_EVRC);
115 if (rc < 0) {
116 pr_err("NT mode Open failed rc=%d\n", rc);
117 rc = -ENODEV;
118 goto fail;
119 }
120 audio->feedback = NON_TUNNEL_MODE;
121 audio->buf_cfg.frames_per_buf = 0x01;
122 audio->buf_cfg.meta_info_enable = 0x01;
123 } else if ((file->f_mode & FMODE_WRITE) &&
124 !(file->f_mode & FMODE_READ)) {
125 rc = q6asm_open_write(audio->ac, FORMAT_EVRC);
126 if (rc < 0) {
127 pr_err("T mode Open failed rc=%d\n", rc);
128 rc = -ENODEV;
129 goto fail;
130 }
131 audio->feedback = TUNNEL_MODE;
132 audio->buf_cfg.meta_info_enable = 0x00;
133 } else {
134 pr_err("Not supported mode\n");
135 rc = -EACCES;
136 goto fail;
137 }
138
139#ifdef CONFIG_DEBUG_FS
140 snprintf(name, sizeof(name), "msm_evrc_%04x", audio->ac->session);
141 audio->dentry = debugfs_create_file(name, S_IFREG | 0444,
142 NULL, (void *)audio,
143 &audio_evrc_debug_fops);
144
145 if (IS_ERR(audio->dentry))
146 pr_debug("debugfs_create_file failed\n");
147#endif
148 pr_info("%s:dec success mode[%d]session[%d]\n", __func__,
149 audio->feedback,
150 audio->ac->session);
151 return rc;
152fail:
153 q6asm_audio_client_free(audio->ac);
154 kfree(audio);
155 return rc;
156}
157
158static const struct file_operations audio_evrc_fops = {
159 .owner = THIS_MODULE,
160 .open = audio_open,
161 .release = audio_aio_release,
162 .unlocked_ioctl = audio_ioctl,
163 .fsync = audio_aio_fsync,
164};
165
166static struct miscdevice audio_evrc_misc = {
167 .minor = MISC_DYNAMIC_MINOR,
168 .name = "msm_evrc",
169 .fops = &audio_evrc_fops,
170};
171
Laxminath Kasam8b1366a2017-10-05 01:44:16 +0530172int __init audio_evrc_init(void)
Asish Bhattacharya8e2277f2017-07-20 18:31:55 +0530173{
174 int ret = misc_register(&audio_evrc_misc);
175
176 if (ret == 0)
177 device_init_wakeup(audio_evrc_misc.this_device, true);
178 audio_evrc_ws_mgr.ref_cnt = 0;
179 mutex_init(&audio_evrc_ws_mgr.ws_lock);
180
181 return ret;
182}
183
Asish Bhattacharya5faacb32017-12-04 17:23:15 +0530184void audio_evrc_exit(void)
Laxminath Kasam8b1366a2017-10-05 01:44:16 +0530185{
186 mutex_destroy(&audio_evrc_ws_mgr.ws_lock);
187 misc_deregister(&audio_evrc_misc);
188}