blob: 1d1da1a2ca823fc85ed8bef2b998c8b9c733d3ca [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* wma 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) 2009-2012, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006 *
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
Deepa Madiregama11786232011-09-13 05:29:41 +053018#include <linux/types.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070019#include <linux/msm_audio_wma.h>
Deepa Madiregama11786232011-09-13 05:29:41 +053020#include "audio_utils_aio.h"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070021
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070022#ifdef CONFIG_DEBUG_FS
Deepa Madiregama11786232011-09-13 05:29:41 +053023static const struct file_operations audio_wma_debug_fops = {
24 .read = audio_aio_debug_read,
25 .open = audio_aio_debug_open,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070026};
27#endif
28
29static long audio_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
30{
Deepa Madiregama11786232011-09-13 05:29:41 +053031 struct q6audio_aio *audio = file->private_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070032 int rc = 0;
33
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070034 switch (cmd) {
35 case AUDIO_START: {
36 struct asm_wma_cfg wma_cfg;
Deepa Madiregama11786232011-09-13 05:29:41 +053037 struct msm_audio_wma_config_v2 *wma_config;
38 pr_debug("%s[%p]: AUDIO_START session_id[%d]\n", __func__,
39 audio, audio->ac->session);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070040 if (audio->feedback == NON_TUNNEL_MODE) {
41 /* Configure PCM output block */
42 rc = q6asm_enc_cfg_blk_pcm(audio->ac,
43 audio->pcm_cfg.sample_rate,
44 audio->pcm_cfg.channel_count);
45 if (rc < 0) {
46 pr_err("pcm output block config failed\n");
47 break;
48 }
49 }
Deepa Madiregama11786232011-09-13 05:29:41 +053050 wma_config = (struct msm_audio_wma_config_v2 *)audio->codec_cfg;
51 wma_cfg.format_tag = wma_config->format_tag;
52 wma_cfg.ch_cfg = wma_config->numchannels;
53 wma_cfg.sample_rate = wma_config->samplingrate;
54 wma_cfg.avg_bytes_per_sec = wma_config->avgbytespersecond;
55 wma_cfg.block_align = wma_config->block_align;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070056 wma_cfg.valid_bits_per_sample =
Deepa Madiregama11786232011-09-13 05:29:41 +053057 wma_config->validbitspersample;
58 wma_cfg.ch_mask = wma_config->channelmask;
59 wma_cfg.encode_opt = wma_config->encodeopt;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070060 /* Configure Media format block */
61 rc = q6asm_media_format_block_wma(audio->ac, &wma_cfg);
62 if (rc < 0) {
63 pr_err("cmd media format block failed\n");
64 break;
65 }
Deepa Madiregama11786232011-09-13 05:29:41 +053066 rc = audio_aio_enable(audio);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070067 audio->eos_rsp = 0;
68 audio->eos_flag = 0;
69 if (!rc) {
70 audio->enabled = 1;
71 } else {
72 audio->enabled = 0;
73 pr_err("Audio Start procedure failed rc=%d\n", rc);
74 break;
75 }
76 pr_debug("AUDIO_START success enable[%d]\n", audio->enabled);
77 if (audio->stopped == 1)
78 audio->stopped = 0;
79 break;
80 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070081 case AUDIO_GET_WMA_CONFIG_V2: {
Deepa Madiregama11786232011-09-13 05:29:41 +053082 if (copy_to_user((void *)arg, audio->codec_cfg,
83 sizeof(struct msm_audio_wma_config_v2))) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070084 rc = -EFAULT;
85 break;
86 }
87 break;
88 }
89 case AUDIO_SET_WMA_CONFIG_V2: {
Deepa Madiregama11786232011-09-13 05:29:41 +053090 if (copy_from_user(audio->codec_cfg, (void *)arg,
91 sizeof(struct msm_audio_wma_config_v2))) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070092 rc = -EFAULT;
93 break;
94 }
95 break;
96 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070097 default:
Deepa Madiregama11786232011-09-13 05:29:41 +053098 pr_debug("%s[%p]: Calling utils ioctl\n", __func__, audio);
99 rc = audio->codec_ioctl(file, cmd, arg);
100 if (rc)
101 pr_err("Failed in utils_ioctl: %d\n", rc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700102 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700103 return rc;
104}
105
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700106static int audio_open(struct inode *inode, struct file *file)
107{
Deepa Madiregama11786232011-09-13 05:29:41 +0530108 struct q6audio_aio *audio = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700109 int rc = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700110
111#ifdef CONFIG_DEBUG_FS
112 /* 4 bytes represents decoder number, 1 byte for terminate string */
113 char name[sizeof "msm_wma_" + 5];
114#endif
Deepa Madiregama11786232011-09-13 05:29:41 +0530115 audio = kzalloc(sizeof(struct q6audio_aio), GFP_KERNEL);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700116
117 if (audio == NULL) {
118 pr_err("Could not allocate memory for wma decode driver\n");
119 return -ENOMEM;
120 }
Deepa Madiregama11786232011-09-13 05:29:41 +0530121 audio->codec_cfg = kzalloc(sizeof(struct msm_audio_wma_config_v2),
122 GFP_KERNEL);
123 if (audio->codec_cfg == NULL) {
Harmandeep Singhc35fa07d2012-05-31 07:08:59 -0700124 pr_err("%s:Could not allocate memory for wma"
125 "config\n", __func__);
Deepa Madiregama11786232011-09-13 05:29:41 +0530126 kfree(audio);
127 return -ENOMEM;
128 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700129
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700130 audio->pcm_cfg.buffer_size = PCM_BUFSZ_MIN;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700131
Harmandeep Singhc35fa07d2012-05-31 07:08:59 -0700132 audio->ac = q6asm_audio_client_alloc((app_cb) q6_audio_cb,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700133 (void *)audio);
134
135 if (!audio->ac) {
136 pr_err("Could not allocate memory for audio client\n");
Deepa Madiregama11786232011-09-13 05:29:41 +0530137 kfree(audio->codec_cfg);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700138 kfree(audio);
139 return -ENOMEM;
140 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700141 /* open in T/NT mode */
142 if ((file->f_mode & FMODE_WRITE) && (file->f_mode & FMODE_READ)) {
143 rc = q6asm_open_read_write(audio->ac, FORMAT_LINEAR_PCM,
144 FORMAT_WMA_V9);
145 if (rc < 0) {
146 pr_err("NT mode Open failed rc=%d\n", rc);
147 rc = -ENODEV;
148 goto fail;
149 }
150 audio->feedback = NON_TUNNEL_MODE;
151 /* open WMA decoder, expected frames is always 1*/
152 audio->buf_cfg.frames_per_buf = 0x01;
153 audio->buf_cfg.meta_info_enable = 0x01;
154 } else if ((file->f_mode & FMODE_WRITE) &&
155 !(file->f_mode & FMODE_READ)) {
156 rc = q6asm_open_write(audio->ac, FORMAT_WMA_V9);
157 if (rc < 0) {
158 pr_err("T mode Open failed rc=%d\n", rc);
159 rc = -ENODEV;
160 goto fail;
161 }
162 audio->feedback = TUNNEL_MODE;
163 audio->buf_cfg.meta_info_enable = 0x00;
164 } else {
165 pr_err("Not supported mode\n");
166 rc = -EACCES;
167 goto fail;
168 }
Deepa Madiregama11786232011-09-13 05:29:41 +0530169 rc = audio_aio_open(audio, file);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700170
171#ifdef CONFIG_DEBUG_FS
172 snprintf(name, sizeof name, "msm_wma_%04x", audio->ac->session);
173 audio->dentry = debugfs_create_file(name, S_IFREG | S_IRUGO,
174 NULL, (void *)audio,
Deepa Madiregama11786232011-09-13 05:29:41 +0530175 &audio_wma_debug_fops);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700176
177 if (IS_ERR(audio->dentry))
178 pr_debug("debugfs_create_file failed\n");
179#endif
Deepa Madiregama11786232011-09-13 05:29:41 +0530180 pr_info("%s:wmadec success mode[%d]session[%d]\n", __func__,
181 audio->feedback,
182 audio->ac->session);
183 return rc;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700184fail:
185 q6asm_audio_client_free(audio->ac);
Deepa Madiregama11786232011-09-13 05:29:41 +0530186 kfree(audio->codec_cfg);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700187 kfree(audio);
188 return rc;
189}
190
191static const struct file_operations audio_wma_fops = {
192 .owner = THIS_MODULE,
193 .open = audio_open,
Deepa Madiregama11786232011-09-13 05:29:41 +0530194 .release = audio_aio_release,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700195 .unlocked_ioctl = audio_ioctl,
Deepa Madiregama11786232011-09-13 05:29:41 +0530196 .fsync = audio_aio_fsync,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700197};
198
Deepa Madiregama11786232011-09-13 05:29:41 +0530199struct miscdevice audio_wma_misc = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700200 .minor = MISC_DYNAMIC_MINOR,
201 .name = "msm_wma",
202 .fops = &audio_wma_fops,
203};
204
205static int __init audio_wma_init(void)
206{
Deepa Madiregama11786232011-09-13 05:29:41 +0530207 return misc_register(&audio_wma_misc);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700208}
209
210device_initcall(audio_wma_init);