blob: f7d54ccac160af63e5912d83cb1c102a8b8cac3c [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* audio_wma.c - wma audio decoder driver
2 *
Manish Dewangana4f1df02012-02-08 17:06:54 +05303 * Copyright (c) 2009, 2011-2012, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004 *
5 * Based on the mp3 native driver in arch/arm/mach-msm/qdsp5/audio_mp3.c
6 *
7 * Copyright (C) 2008 Google, Inc.
8 * Copyright (C) 2008 HTC Corporation
9 *
10 * All source code in this file is licensed under the following license except
11 * where indicated.
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License version 2 as published
15 * by the Free Software Foundation.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * See the GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, you can find it at http://www.fsf.org
24 */
25
Santosh Mardi0be3b8e2011-07-06 10:00:21 +053026#include <asm/atomic.h>
27#include <asm/ioctls.h>
28
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070029#include <linux/module.h>
30#include <linux/fs.h>
31#include <linux/miscdevice.h>
32#include <linux/uaccess.h>
33#include <linux/kthread.h>
34#include <linux/wait.h>
35#include <linux/dma-mapping.h>
36#include <linux/debugfs.h>
37#include <linux/delay.h>
38#include <linux/list.h>
39#include <linux/earlysuspend.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070040#include <linux/slab.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070041#include <linux/msm_audio.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070042#include <linux/msm_audio_wma.h>
Santosh Mardi0be3b8e2011-07-06 10:00:21 +053043#include <linux/memory_alloc.h>
Mitchel Humpherys1da6ebe2012-09-06 10:15:56 -070044#include <linux/msm_ion.h>
Santosh Mardi0be3b8e2011-07-06 10:00:21 +053045
46#include <mach/msm_adsp.h>
47#include <mach/iommu.h>
48#include <mach/iommu_domains.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070049#include <mach/qdsp5/qdsp5audppcmdi.h>
50#include <mach/qdsp5/qdsp5audppmsg.h>
Manish Dewanganfa8a6b62012-07-09 16:23:27 +053051#include <mach/qdsp5/qdsp5audpp.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070052#include <mach/qdsp5/qdsp5audplaycmdi.h>
53#include <mach/qdsp5/qdsp5audplaymsg.h>
54#include <mach/qdsp5/qdsp5rmtcmdi.h>
55#include <mach/debug_mm.h>
Santosh Mardi0be3b8e2011-07-06 10:00:21 +053056#include <mach/msm_memtypes.h>
57
58#include "audmgr.h"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070059
60/* Size must be power of 2 */
61#define BUFSZ_MAX 2062 /* Includes meta in size */
62#define BUFSZ_MIN 1038 /* Includes meta in size */
63#define DMASZ_MAX (BUFSZ_MAX * 2)
64#define DMASZ_MIN (BUFSZ_MIN * 2)
65
66#define AUDPLAY_INVALID_READ_PTR_OFFSET 0xFFFF
67#define AUDDEC_DEC_WMA 4
68
69#define PCM_BUFSZ_MIN 8216 /* Hold one stereo WMA frame and meta out*/
70#define PCM_BUF_MAX_COUNT 5 /* DSP only accepts 5 buffers at most
71 but support 2 buffers currently */
72#define ROUTING_MODE_FTRT 1
73#define ROUTING_MODE_RT 2
74/* Decoder status received from AUDPPTASK */
75#define AUDPP_DEC_STATUS_SLEEP 0
76#define AUDPP_DEC_STATUS_INIT 1
77#define AUDPP_DEC_STATUS_CFG 2
78#define AUDPP_DEC_STATUS_PLAY 3
79
80#define AUDWMA_METAFIELD_MASK 0xFFFF0000
81#define AUDWMA_EOS_FLG_OFFSET 0x0A /* Offset from beginning of buffer */
82#define AUDWMA_EOS_FLG_MASK 0x01
83#define AUDWMA_EOS_NONE 0x0 /* No EOS detected */
84#define AUDWMA_EOS_SET 0x1 /* EOS set in meta field */
85
86#define AUDWMA_EVENT_NUM 10 /* Default number of pre-allocated event packets */
87
88struct buffer {
89 void *data;
90 unsigned size;
91 unsigned used; /* Input usage actual DSP produced PCM size */
92 unsigned addr;
93 unsigned short mfield_sz; /*only useful for data has meta field */
94};
95
96#ifdef CONFIG_HAS_EARLYSUSPEND
97struct audwma_suspend_ctl {
98 struct early_suspend node;
99 struct audio *audio;
100};
101#endif
102
103struct audwma_event{
104 struct list_head list;
105 int event_type;
106 union msm_audio_event_payload payload;
107};
108
109struct audio {
110 struct buffer out[2];
111
112 spinlock_t dsp_lock;
113
114 uint8_t out_head;
115 uint8_t out_tail;
116 uint8_t out_needed; /* number of buffers the dsp is waiting for */
117 unsigned out_dma_sz;
118
119 atomic_t out_bytes;
120
121 struct mutex lock;
122 struct mutex write_lock;
123 wait_queue_head_t write_wait;
124
125 /* Host PCM section */
126 struct buffer in[PCM_BUF_MAX_COUNT];
127 struct mutex read_lock;
128 wait_queue_head_t read_wait; /* Wait queue for read */
129 char *read_data; /* pointer to reader buffer */
130 int32_t read_phys; /* physical address of reader buffer */
131 uint8_t read_next; /* index to input buffers to be read next */
132 uint8_t fill_next; /* index to buffer that DSP should be filling */
133 uint8_t pcm_buf_count; /* number of pcm buffer allocated */
134 /* ---- End of Host PCM section */
135
136 struct msm_adsp_module *audplay;
137
138 /* configuration to use on next enable */
139 uint32_t out_sample_rate;
140 uint32_t out_channel_mode;
141
142 struct msm_audio_wma_config wma_config;
143 struct audmgr audmgr;
144
145 /* data allocated for various buffers */
146 char *data;
147 int32_t phys; /* physical address of write buffer */
Laura Abbott35111d32012-04-27 18:41:48 -0700148 void *map_v_read;
149 void *map_v_write;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700150
151 int mfield; /* meta field embedded in data */
152 int rflush; /* Read flush */
153 int wflush; /* Write flush */
154 int opened;
155 int enabled;
156 int running;
157 int stopped; /* set when stopped, cleared on flush */
158 int pcm_feedback;
159 int buf_refresh;
160 int rmt_resource_released;
161 int teos; /* valid only if tunnel mode & no data left for decoder */
162 enum msm_aud_decoder_state dec_state; /* Represents decoder state */
163 int reserved; /* A byte is being reserved */
164 char rsv_byte; /* Handle odd length user data */
165
166 const char *module_name;
167 unsigned queue_id;
168 uint16_t dec_id;
169 uint32_t read_ptr_offset;
170
171#ifdef CONFIG_HAS_EARLYSUSPEND
172 struct audwma_suspend_ctl suspend_ctl;
173#endif
174
175#ifdef CONFIG_DEBUG_FS
176 struct dentry *dentry;
177#endif
178
179 wait_queue_head_t wait;
180 struct list_head free_event_queue;
181 struct list_head event_queue;
182 wait_queue_head_t event_wait;
183 spinlock_t event_queue_lock;
184 struct mutex get_event_lock;
185 int event_abort;
186
187 int eq_enable;
188 int eq_needs_commit;
189 audpp_cmd_cfg_object_params_eqalizer eq;
190 audpp_cmd_cfg_object_params_volume vol_pan;
Sidipotu Ashok172c98b2012-06-26 17:58:29 +0530191 struct ion_client *client;
192 struct ion_handle *input_buff_handle;
193 struct ion_handle *output_buff_handle;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700194};
195
196static int auddec_dsp_config(struct audio *audio, int enable);
197static void audpp_cmd_cfg_adec_params(struct audio *audio);
198static void audpp_cmd_cfg_routing_mode(struct audio *audio);
199static void audplay_send_data(struct audio *audio, unsigned needed);
200static void audplay_config_hostpcm(struct audio *audio);
201static void audplay_buffer_refresh(struct audio *audio);
202static void audio_dsp_event(void *private, unsigned id, uint16_t *msg);
203#ifdef CONFIG_HAS_EARLYSUSPEND
204static void audwma_post_event(struct audio *audio, int type,
205 union msm_audio_event_payload payload);
206#endif
207
208static int rmt_put_resource(struct audio *audio)
209{
210 struct aud_codec_config_cmd cmd;
211 unsigned short client_idx;
212
213 cmd.cmd_id = RM_CMD_AUD_CODEC_CFG;
214 cmd.client_id = RM_AUD_CLIENT_ID;
215 cmd.task_id = audio->dec_id;
216 cmd.enable = RMT_DISABLE;
217 cmd.dec_type = AUDDEC_DEC_WMA;
218 client_idx = ((cmd.client_id << 8) | cmd.task_id);
219
220 return put_adsp_resource(client_idx, &cmd, sizeof(cmd));
221}
222
223static int rmt_get_resource(struct audio *audio)
224{
225 struct aud_codec_config_cmd cmd;
226 unsigned short client_idx;
227
228 cmd.cmd_id = RM_CMD_AUD_CODEC_CFG;
229 cmd.client_id = RM_AUD_CLIENT_ID;
230 cmd.task_id = audio->dec_id;
231 cmd.enable = RMT_ENABLE;
232 cmd.dec_type = AUDDEC_DEC_WMA;
233 client_idx = ((cmd.client_id << 8) | cmd.task_id);
234
235 return get_adsp_resource(client_idx, &cmd, sizeof(cmd));
236}
237
238/* must be called with audio->lock held */
239static int audio_enable(struct audio *audio)
240{
241 struct audmgr_config cfg;
242 int rc;
243
244 MM_DBG("\n"); /* Macro prints the file name and function */
245 if (audio->enabled)
246 return 0;
247
248 if (audio->rmt_resource_released == 1) {
249 audio->rmt_resource_released = 0;
250 rc = rmt_get_resource(audio);
251 if (rc) {
252 MM_ERR("ADSP resources are not available for WMA \
253 session 0x%08x on decoder: %d\n Ignoring \
254 error and going ahead with the playback\n",
255 (int)audio, audio->dec_id);
256 }
257 }
258
259 audio->dec_state = MSM_AUD_DECODER_STATE_NONE;
260 audio->out_tail = 0;
261 audio->out_needed = 0;
262
263 if (audio->pcm_feedback == TUNNEL_MODE_PLAYBACK) {
264 cfg.tx_rate = RPC_AUD_DEF_SAMPLE_RATE_NONE;
265 cfg.rx_rate = RPC_AUD_DEF_SAMPLE_RATE_48000;
266 cfg.def_method = RPC_AUD_DEF_METHOD_PLAYBACK;
267 cfg.codec = RPC_AUD_DEF_CODEC_WMA;
268 cfg.snd_method = RPC_SND_METHOD_MIDI;
269
270 rc = audmgr_enable(&audio->audmgr, &cfg);
=Chaithanya Krishna Bacharajub5c4e982012-12-06 09:53:18 +0530271 if (rc < 0) {
272 msm_adsp_dump(audio->audplay);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700273 return rc;
=Chaithanya Krishna Bacharajub5c4e982012-12-06 09:53:18 +0530274 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700275 }
276
277 if (msm_adsp_enable(audio->audplay)) {
278 MM_ERR("msm_adsp_enable(audplay) failed\n");
279 if (audio->pcm_feedback == TUNNEL_MODE_PLAYBACK)
280 audmgr_disable(&audio->audmgr);
281 return -ENODEV;
282 }
283
284 if (audpp_enable(audio->dec_id, audio_dsp_event, audio)) {
285 MM_ERR("audpp_enable() failed\n");
286 msm_adsp_disable(audio->audplay);
287 if (audio->pcm_feedback == TUNNEL_MODE_PLAYBACK)
288 audmgr_disable(&audio->audmgr);
289 return -ENODEV;
290 }
291
292 audio->enabled = 1;
293 return 0;
294}
295
296/* must be called with audio->lock held */
297static int audio_disable(struct audio *audio)
298{
299 int rc = 0;
300 MM_DBG("\n"); /* Macro prints the file name and function */
301 if (audio->enabled) {
302 audio->enabled = 0;
303 audio->dec_state = MSM_AUD_DECODER_STATE_NONE;
304 auddec_dsp_config(audio, 0);
305 rc = wait_event_interruptible_timeout(audio->wait,
306 audio->dec_state != MSM_AUD_DECODER_STATE_NONE,
307 msecs_to_jiffies(MSM_AUD_DECODER_WAIT_MS));
308 if (rc == 0)
309 rc = -ETIMEDOUT;
310 else if (audio->dec_state != MSM_AUD_DECODER_STATE_CLOSE)
311 rc = -EFAULT;
312 else
313 rc = 0;
Manish Dewangan89a9f232012-02-09 17:14:40 +0530314 audio->stopped = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700315 wake_up(&audio->write_wait);
316 wake_up(&audio->read_wait);
317 msm_adsp_disable(audio->audplay);
318 audpp_disable(audio->dec_id, audio);
=Chaithanya Krishna Bacharajub5c4e982012-12-06 09:53:18 +0530319 if (audio->pcm_feedback == TUNNEL_MODE_PLAYBACK) {
320 rc = audmgr_disable(&audio->audmgr);
321 if (rc < 0)
322 msm_adsp_dump(audio->audplay);
323 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700324 audio->out_needed = 0;
325 rmt_put_resource(audio);
326 audio->rmt_resource_released = 1;
327 }
328 return rc;
329}
330
331/* ------------------- dsp --------------------- */
332static void audio_update_pcm_buf_entry(struct audio *audio,
333 uint32_t *payload)
334{
335 uint8_t index;
336 unsigned long flags;
337
338 if (audio->rflush)
339 return;
340
341 spin_lock_irqsave(&audio->dsp_lock, flags);
342 for (index = 0; index < payload[1]; index++) {
343 if (audio->in[audio->fill_next].addr ==
344 payload[2 + index * 2]) {
345 MM_DBG("audio_update_pcm_buf_entry: \
346 in[%d] ready\n", audio->fill_next);
347 audio->in[audio->fill_next].used =
348 payload[3 + index * 2];
349 if ((++audio->fill_next) == audio->pcm_buf_count)
350 audio->fill_next = 0;
351 } else {
352 MM_ERR("audio_update_pcm_buf_entry: \
353 expected=%x ret=%x\n",
354 audio->in[audio->fill_next].addr,
355 payload[1 + index * 2]);
356 break;
357 }
358 }
359 if (audio->in[audio->fill_next].used == 0) {
360 audplay_buffer_refresh(audio);
361 } else {
362 MM_DBG("read cannot keep up\n");
363 audio->buf_refresh = 1;
364 }
365 wake_up(&audio->read_wait);
366 spin_unlock_irqrestore(&audio->dsp_lock, flags);
367}
368
369static void audplay_dsp_event(void *data, unsigned id, size_t len,
370 void (*getevent) (void *ptr, size_t len))
371{
372 struct audio *audio = data;
373 uint32_t msg[28];
374
375 getevent(msg, sizeof(msg));
376
377 MM_DBG("msg_id=%x\n", id);
378
379 switch (id) {
380 case AUDPLAY_MSG_DEC_NEEDS_DATA:
381 audplay_send_data(audio, 1);
382 break;
383
384 case AUDPLAY_MSG_BUFFER_UPDATE:
385 audio_update_pcm_buf_entry(audio, msg);
386 break;
387
388 case ADSP_MESSAGE_ID:
389 MM_DBG("Received ADSP event: module enable(audplaytask)\n");
390 break;
391
392 default:
393 MM_ERR("unexpected message from decoder \n");
394 break;
395 }
396}
397
398static void audio_dsp_event(void *private, unsigned id, uint16_t *msg)
399{
400 struct audio *audio = private;
401
402 switch (id) {
403 case AUDPP_MSG_STATUS_MSG:{
404 unsigned status = msg[1];
405
406 switch (status) {
407 case AUDPP_DEC_STATUS_SLEEP: {
408 uint16_t reason = msg[2];
409 MM_DBG("decoder status:sleep reason = \
410 0x%04x\n", reason);
411 if ((reason == AUDPP_MSG_REASON_MEM)
412 || (reason ==
413 AUDPP_MSG_REASON_NODECODER)) {
414 audio->dec_state =
415 MSM_AUD_DECODER_STATE_FAILURE;
416 wake_up(&audio->wait);
417 } else if (reason == AUDPP_MSG_REASON_NONE) {
418 /* decoder is in disable state */
419 audio->dec_state =
420 MSM_AUD_DECODER_STATE_CLOSE;
421 wake_up(&audio->wait);
422 }
423 break;
424 }
425 case AUDPP_DEC_STATUS_INIT:
426 MM_DBG("decoder status: init\n");
427 if (audio->pcm_feedback)
428 audpp_cmd_cfg_routing_mode(audio);
429 else
430 audpp_cmd_cfg_adec_params(audio);
431 break;
432
433 case AUDPP_DEC_STATUS_CFG:
434 MM_DBG("decoder status: cfg\n");
435 break;
436 case AUDPP_DEC_STATUS_PLAY:
437 MM_DBG("decoder status: play\n");
438 if (audio->pcm_feedback) {
439 audplay_config_hostpcm(audio);
440 audplay_buffer_refresh(audio);
441 }
442 audio->dec_state =
443 MSM_AUD_DECODER_STATE_SUCCESS;
444 wake_up(&audio->wait);
445 break;
446 default:
447 MM_ERR("unknown decoder status\n");
448 }
449 break;
450 }
451 case AUDPP_MSG_CFG_MSG:
452 if (msg[0] == AUDPP_MSG_ENA_ENA) {
453 MM_DBG("CFG_MSG ENABLE\n");
454 auddec_dsp_config(audio, 1);
455 audio->out_needed = 0;
456 audio->running = 1;
457 audpp_dsp_set_vol_pan(audio->dec_id, &audio->vol_pan);
458 audpp_dsp_set_eq(audio->dec_id, audio->eq_enable,
459 &audio->eq);
460 audpp_avsync(audio->dec_id, 22050);
461 } else if (msg[0] == AUDPP_MSG_ENA_DIS) {
462 MM_DBG("CFG_MSG DISABLE\n");
463 audpp_avsync(audio->dec_id, 0);
464 audio->running = 0;
465 } else {
466 MM_DBG("CFG_MSG %d?\n", msg[0]);
467 }
468 break;
469 case AUDPP_MSG_ROUTING_ACK:
470 MM_DBG("ROUTING_ACK mode=%d\n", msg[1]);
471 audpp_cmd_cfg_adec_params(audio);
472 break;
473
474 case AUDPP_MSG_FLUSH_ACK:
475 MM_DBG("FLUSH_ACK\n");
476 audio->wflush = 0;
477 audio->rflush = 0;
478 wake_up(&audio->write_wait);
479 if (audio->pcm_feedback)
480 audplay_buffer_refresh(audio);
Phani Kumar Alladaee940eb2012-05-10 11:13:04 +0530481 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700482 case AUDPP_MSG_PCMDMAMISSED:
483 MM_DBG("PCMDMAMISSED\n");
484 audio->teos = 1;
485 wake_up(&audio->write_wait);
486 break;
487
488 default:
489 MM_ERR("UNKNOWN (%d)\n", id);
490 }
491
492}
493
494static struct msm_adsp_ops audplay_adsp_ops_wma = {
495 .event = audplay_dsp_event,
496};
497
498#define audplay_send_queue0(audio, cmd, len) \
499 msm_adsp_write(audio->audplay, audio->queue_id, \
500 cmd, len)
501
502static int auddec_dsp_config(struct audio *audio, int enable)
503{
504 u16 cfg_dec_cmd[AUDPP_CMD_CFG_DEC_TYPE_LEN / sizeof(unsigned short)];
505
506 memset(cfg_dec_cmd, 0, sizeof(cfg_dec_cmd));
507 cfg_dec_cmd[0] = AUDPP_CMD_CFG_DEC_TYPE;
508 if (enable)
509 cfg_dec_cmd[1 + audio->dec_id] = AUDPP_CMD_UPDATDE_CFG_DEC |
510 AUDPP_CMD_ENA_DEC_V | AUDDEC_DEC_WMA;
511 else
512 cfg_dec_cmd[1 + audio->dec_id] = AUDPP_CMD_UPDATDE_CFG_DEC |
513 AUDPP_CMD_DIS_DEC_V;
514
515 return audpp_send_queue1(&cfg_dec_cmd, sizeof(cfg_dec_cmd));
516}
517
518static void audpp_cmd_cfg_adec_params(struct audio *audio)
519{
520 struct audpp_cmd_cfg_adec_params_wma cmd;
521
522 memset(&cmd, 0, sizeof(cmd));
523 cmd.common.cmd_id = AUDPP_CMD_CFG_ADEC_PARAMS;
524 cmd.common.length = AUDPP_CMD_CFG_ADEC_PARAMS_WMA_LEN;
525 cmd.common.dec_id = audio->dec_id;
526 cmd.common.input_sampling_frequency = audio->out_sample_rate;
527
528 /*
529 * Test done for sample with the following configuration
530 * armdatareqthr = 1262
531 * channelsdecoded = 1(MONO)/2(STEREO)
532 * wmabytespersec = Tested with 6003 Bytes per sec
533 * wmasamplingfreq = 44100
534 * wmaencoderopts = 31
535 */
536
537 cmd.armdatareqthr = audio->wma_config.armdatareqthr;
538 cmd.channelsdecoded = audio->wma_config.channelsdecoded;
539 cmd.wmabytespersec = audio->wma_config.wmabytespersec;
540 cmd.wmasamplingfreq = audio->wma_config.wmasamplingfreq;
541 cmd.wmaencoderopts = audio->wma_config.wmaencoderopts;
542
543 audpp_send_queue2(&cmd, sizeof(cmd));
544}
545
546static void audpp_cmd_cfg_routing_mode(struct audio *audio)
547{
548 struct audpp_cmd_routing_mode cmd;
549
550 MM_DBG("\n"); /* Macro prints the file name and function */
551 memset(&cmd, 0, sizeof(cmd));
552 cmd.cmd_id = AUDPP_CMD_ROUTING_MODE;
553 cmd.object_number = audio->dec_id;
554 if (audio->pcm_feedback)
555 cmd.routing_mode = ROUTING_MODE_FTRT;
556 else
557 cmd.routing_mode = ROUTING_MODE_RT;
558
559 audpp_send_queue1(&cmd, sizeof(cmd));
560}
561
562static void audplay_buffer_refresh(struct audio *audio)
563{
564 struct audplay_cmd_buffer_refresh refresh_cmd;
565
566 refresh_cmd.cmd_id = AUDPLAY_CMD_BUFFER_REFRESH;
567 refresh_cmd.num_buffers = 1;
568 refresh_cmd.buf0_address = audio->in[audio->fill_next].addr;
569 refresh_cmd.buf0_length = audio->in[audio->fill_next].size;
570 refresh_cmd.buf_read_count = 0;
571
572 MM_DBG("buf0_addr=%x buf0_len=%d\n",
573 refresh_cmd.buf0_address,
574 refresh_cmd.buf0_length);
575
576 (void)audplay_send_queue0(audio, &refresh_cmd, sizeof(refresh_cmd));
577}
578
579static void audplay_config_hostpcm(struct audio *audio)
580{
581 struct audplay_cmd_hpcm_buf_cfg cfg_cmd;
582
583 MM_DBG("\n"); /* Macro prints the file name and function */
584 cfg_cmd.cmd_id = AUDPLAY_CMD_HPCM_BUF_CFG;
585 cfg_cmd.max_buffers = audio->pcm_buf_count;
586 cfg_cmd.byte_swap = 0;
587 cfg_cmd.hostpcm_config = (0x8000) | (0x4000);
588 cfg_cmd.feedback_frequency = 1;
589 cfg_cmd.partition_number = 0;
590
591 (void)audplay_send_queue0(audio, &cfg_cmd, sizeof(cfg_cmd));
592}
593
594
595static int audplay_dsp_send_data_avail(struct audio *audio,
596 unsigned idx, unsigned len)
597{
598 struct audplay_cmd_bitstream_data_avail_nt2 cmd;
599
600 cmd.cmd_id = AUDPLAY_CMD_BITSTREAM_DATA_AVAIL_NT2;
601 if (audio->mfield)
602 cmd.decoder_id = AUDWMA_METAFIELD_MASK |
603 (audio->out[idx].mfield_sz >> 1);
604 else
605 cmd.decoder_id = audio->dec_id;
606 cmd.buf_ptr = audio->out[idx].addr;
607 cmd.buf_size = len/2;
608 cmd.partition_number = 0;
609 /* complete writes to the input buffer */
610 wmb();
611 return audplay_send_queue0(audio, &cmd, sizeof(cmd));
612}
613
614static void audplay_send_data(struct audio *audio, unsigned needed)
615{
616 struct buffer *frame;
617 unsigned long flags;
618
619 spin_lock_irqsave(&audio->dsp_lock, flags);
620 if (!audio->running)
621 goto done;
622
623 if (audio->wflush) {
624 audio->out_needed = 1;
625 goto done;
626 }
627
628 if (needed && !audio->wflush) {
629 /* We were called from the callback because the DSP
630 * requested more data. Note that the DSP does want
631 * more data, and if a buffer was in-flight, mark it
632 * as available (since the DSP must now be done with
633 * it).
634 */
635 audio->out_needed = 1;
636 frame = audio->out + audio->out_tail;
637 if (frame->used == 0xffffffff) {
638 MM_DBG("frame %d free\n", audio->out_tail);
639 frame->used = 0;
640 audio->out_tail ^= 1;
641 wake_up(&audio->write_wait);
642 }
643 }
644
645 if (audio->out_needed) {
646 /* If the DSP currently wants data and we have a
647 * buffer available, we will send it and reset
648 * the needed flag. We'll mark the buffer as in-flight
649 * so that it won't be recycled until the next buffer
650 * is requested
651 */
652
653 MM_DBG("\n"); /* Macro prints the file name and function */
654 frame = audio->out + audio->out_tail;
655 if (frame->used) {
656 BUG_ON(frame->used == 0xffffffff);
657 MM_DBG("frame %d busy\n", audio->out_tail);
658 audplay_dsp_send_data_avail(audio, audio->out_tail,
659 frame->used);
660 frame->used = 0xffffffff;
661 audio->out_needed = 0;
662 }
663 }
664done:
665 spin_unlock_irqrestore(&audio->dsp_lock, flags);
666}
667
668/* ------------------- device --------------------- */
669
670static void audio_flush(struct audio *audio)
671{
Manish Dewangana4f1df02012-02-08 17:06:54 +0530672 unsigned long flags;
673
674 spin_lock_irqsave(&audio->dsp_lock, flags);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700675 audio->out[0].used = 0;
676 audio->out[1].used = 0;
677 audio->out_head = 0;
678 audio->out_tail = 0;
679 audio->reserved = 0;
Manish Dewangana4f1df02012-02-08 17:06:54 +0530680 spin_unlock_irqrestore(&audio->dsp_lock, flags);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700681 atomic_set(&audio->out_bytes, 0);
682}
683
684static void audio_flush_pcm_buf(struct audio *audio)
685{
686 uint8_t index;
687
Manish Dewangana4f1df02012-02-08 17:06:54 +0530688 unsigned long flags;
689
690 spin_lock_irqsave(&audio->dsp_lock, flags);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700691 for (index = 0; index < PCM_BUF_MAX_COUNT; index++)
692 audio->in[index].used = 0;
693 audio->buf_refresh = 0;
694 audio->read_next = 0;
695 audio->fill_next = 0;
Manish Dewangana4f1df02012-02-08 17:06:54 +0530696 spin_unlock_irqrestore(&audio->dsp_lock, flags);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700697}
698
699static void audio_ioport_reset(struct audio *audio)
700{
701 /* Make sure read/write thread are free from
702 * sleep and knowing that system is not able
703 * to process io request at the moment
704 */
705 wake_up(&audio->write_wait);
706 mutex_lock(&audio->write_lock);
707 audio_flush(audio);
708 mutex_unlock(&audio->write_lock);
709 wake_up(&audio->read_wait);
710 mutex_lock(&audio->read_lock);
711 audio_flush_pcm_buf(audio);
712 mutex_unlock(&audio->read_lock);
713}
714
715static int audwma_events_pending(struct audio *audio)
716{
717 unsigned long flags;
718 int empty;
719
720 spin_lock_irqsave(&audio->event_queue_lock, flags);
721 empty = !list_empty(&audio->event_queue);
722 spin_unlock_irqrestore(&audio->event_queue_lock, flags);
723 return empty || audio->event_abort;
724}
725
726static void audwma_reset_event_queue(struct audio *audio)
727{
728 unsigned long flags;
729 struct audwma_event *drv_evt;
730 struct list_head *ptr, *next;
731
732 spin_lock_irqsave(&audio->event_queue_lock, flags);
733 list_for_each_safe(ptr, next, &audio->event_queue) {
734 drv_evt = list_first_entry(&audio->event_queue,
735 struct audwma_event, list);
736 list_del(&drv_evt->list);
737 kfree(drv_evt);
738 }
739 list_for_each_safe(ptr, next, &audio->free_event_queue) {
740 drv_evt = list_first_entry(&audio->free_event_queue,
741 struct audwma_event, list);
742 list_del(&drv_evt->list);
743 kfree(drv_evt);
744 }
745 spin_unlock_irqrestore(&audio->event_queue_lock, flags);
746
747 return;
748}
749
750static long audwma_process_event_req(struct audio *audio, void __user *arg)
751{
752 long rc;
753 struct msm_audio_event usr_evt;
754 struct audwma_event *drv_evt = NULL;
755 int timeout;
756 unsigned long flags;
757
758 if (copy_from_user(&usr_evt, arg, sizeof(struct msm_audio_event)))
759 return -EFAULT;
760
761 timeout = (int) usr_evt.timeout_ms;
762
763 if (timeout > 0) {
764 rc = wait_event_interruptible_timeout(
765 audio->event_wait, audwma_events_pending(audio),
766 msecs_to_jiffies(timeout));
767 if (rc == 0)
768 return -ETIMEDOUT;
769 } else {
770 rc = wait_event_interruptible(
771 audio->event_wait, audwma_events_pending(audio));
772 }
773
774 if (rc < 0)
775 return rc;
776
777 if (audio->event_abort) {
778 audio->event_abort = 0;
779 return -ENODEV;
780 }
781
782 rc = 0;
783
784 spin_lock_irqsave(&audio->event_queue_lock, flags);
785 if (!list_empty(&audio->event_queue)) {
786 drv_evt = list_first_entry(&audio->event_queue,
787 struct audwma_event, list);
788 list_del(&drv_evt->list);
789 }
790
791 if (drv_evt) {
792 usr_evt.event_type = drv_evt->event_type;
793 usr_evt.event_payload = drv_evt->payload;
794 list_add_tail(&drv_evt->list, &audio->free_event_queue);
795 } else
796 rc = -1;
797 spin_unlock_irqrestore(&audio->event_queue_lock, flags);
798
799 if (!rc && copy_to_user(arg, &usr_evt, sizeof(usr_evt)))
800 rc = -EFAULT;
801
802 return rc;
803}
804
805static int audio_enable_eq(struct audio *audio, int enable)
806{
807 if (audio->eq_enable == enable && !audio->eq_needs_commit)
808 return 0;
809
810 audio->eq_enable = enable;
811
812 if (audio->running) {
813 audpp_dsp_set_eq(audio->dec_id, enable, &audio->eq);
814 audio->eq_needs_commit = 0;
815 }
816 return 0;
817}
818
819static long audio_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
820{
821 struct audio *audio = file->private_data;
822 int rc = -EINVAL;
823 unsigned long flags = 0;
824 uint16_t enable_mask;
825 int enable;
826 int prev_state;
Sidipotu Ashok172c98b2012-06-26 17:58:29 +0530827 unsigned long ionflag = 0;
828 ion_phys_addr_t addr = 0;
829 struct ion_handle *handle = NULL;
830 int len = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700831
832 MM_DBG("cmd = %d\n", cmd);
833
834 if (cmd == AUDIO_GET_STATS) {
835 struct msm_audio_stats stats;
836 stats.byte_count = audpp_avsync_byte_count(audio->dec_id);
837 stats.sample_count = audpp_avsync_sample_count(audio->dec_id);
838 if (copy_to_user((void *)arg, &stats, sizeof(stats)))
839 return -EFAULT;
840 return 0;
841 }
842
843 switch (cmd) {
844 case AUDIO_ENABLE_AUDPP:
845 if (copy_from_user(&enable_mask, (void *) arg,
846 sizeof(enable_mask))) {
847 rc = -EFAULT;
848 break;
849 }
850
851 spin_lock_irqsave(&audio->dsp_lock, flags);
852 enable = (enable_mask & EQ_ENABLE) ? 1 : 0;
853 audio_enable_eq(audio, enable);
854 spin_unlock_irqrestore(&audio->dsp_lock, flags);
855 rc = 0;
856 break;
857 case AUDIO_SET_VOLUME:
858 spin_lock_irqsave(&audio->dsp_lock, flags);
859 audio->vol_pan.volume = arg;
860 if (audio->running)
861 audpp_dsp_set_vol_pan(audio->dec_id, &audio->vol_pan);
862 spin_unlock_irqrestore(&audio->dsp_lock, flags);
863 rc = 0;
864 break;
865
866 case AUDIO_SET_PAN:
867 spin_lock_irqsave(&audio->dsp_lock, flags);
868 audio->vol_pan.pan = arg;
869 if (audio->running)
870 audpp_dsp_set_vol_pan(audio->dec_id, &audio->vol_pan);
871 spin_unlock_irqrestore(&audio->dsp_lock, flags);
872 rc = 0;
873 break;
874
875 case AUDIO_SET_EQ:
876 prev_state = audio->eq_enable;
877 audio->eq_enable = 0;
878 if (copy_from_user(&audio->eq.num_bands, (void *) arg,
879 sizeof(audio->eq) -
880 (AUDPP_CMD_CFG_OBJECT_PARAMS_COMMON_LEN + 2))) {
881 rc = -EFAULT;
882 break;
883 }
884 audio->eq_enable = prev_state;
885 audio->eq_needs_commit = 1;
886 rc = 0;
887 break;
888 }
889
890 if (-EINVAL != rc)
891 return rc;
892
893 if (cmd == AUDIO_GET_EVENT) {
894 MM_DBG("AUDIO_GET_EVENT\n");
895 if (mutex_trylock(&audio->get_event_lock)) {
896 rc = audwma_process_event_req(audio,
897 (void __user *) arg);
898 mutex_unlock(&audio->get_event_lock);
899 } else
900 rc = -EBUSY;
901 return rc;
902 }
903
904 if (cmd == AUDIO_ABORT_GET_EVENT) {
905 audio->event_abort = 1;
906 wake_up(&audio->event_wait);
907 return 0;
908 }
909
910 mutex_lock(&audio->lock);
911 switch (cmd) {
912 case AUDIO_START:
913 MM_DBG("AUDIO_START\n");
914 rc = audio_enable(audio);
915 if (!rc) {
916 rc = wait_event_interruptible_timeout(audio->wait,
917 audio->dec_state != MSM_AUD_DECODER_STATE_NONE,
918 msecs_to_jiffies(MSM_AUD_DECODER_WAIT_MS));
919 MM_INFO("dec_state %d rc = %d\n", audio->dec_state, rc);
920
921 if (audio->dec_state != MSM_AUD_DECODER_STATE_SUCCESS)
922 rc = -ENODEV;
923 else
924 rc = 0;
925 }
926 break;
927 case AUDIO_STOP:
928 MM_DBG("AUDIO_STOP\n");
929 rc = audio_disable(audio);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700930 audio_ioport_reset(audio);
931 audio->stopped = 0;
932 break;
933 case AUDIO_FLUSH:
934 MM_DBG("AUDIO_FLUSH\n");
935 audio->rflush = 1;
936 audio->wflush = 1;
937 audio_ioport_reset(audio);
938 if (audio->running) {
939 audpp_flush(audio->dec_id);
940 rc = wait_event_interruptible(audio->write_wait,
941 !audio->wflush);
942 if (rc < 0) {
943 MM_ERR("AUDIO_FLUSH interrupted\n");
944 rc = -EINTR;
945 }
946 } else {
947 audio->rflush = 0;
948 audio->wflush = 0;
949 }
950 break;
951 case AUDIO_SET_CONFIG: {
952 struct msm_audio_config config;
953 if (copy_from_user(&config, (void *) arg, sizeof(config))) {
954 rc = -EFAULT;
955 break;
956 }
957 if (config.channel_count == 1) {
958 config.channel_count = AUDPP_CMD_PCM_INTF_MONO_V;
959 } else if (config.channel_count == 2) {
960 config.channel_count = AUDPP_CMD_PCM_INTF_STEREO_V;
961 } else {
962 rc = -EINVAL;
963 break;
964 }
965 audio->mfield = config.meta_field;
966 audio->out_sample_rate = config.sample_rate;
967 audio->out_channel_mode = config.channel_count;
968 rc = 0;
969 break;
970 }
971 case AUDIO_GET_CONFIG: {
972 struct msm_audio_config config;
973 config.buffer_size = (audio->out_dma_sz >> 1);
974 config.buffer_count = 2;
975 config.sample_rate = audio->out_sample_rate;
976 if (audio->out_channel_mode == AUDPP_CMD_PCM_INTF_MONO_V)
977 config.channel_count = 1;
978 else
979 config.channel_count = 2;
980 config.meta_field = 0;
981 config.unused[0] = 0;
982 config.unused[1] = 0;
983 config.unused[2] = 0;
984 if (copy_to_user((void *) arg, &config, sizeof(config)))
985 rc = -EFAULT;
986 else
987 rc = 0;
988
989 break;
990 }
991 case AUDIO_GET_WMA_CONFIG:{
992 if (copy_to_user((void *)arg, &audio->wma_config,
993 sizeof(audio->wma_config)))
994 rc = -EFAULT;
995 else
996 rc = 0;
997 break;
998 }
999 case AUDIO_SET_WMA_CONFIG:{
1000 struct msm_audio_wma_config usr_config;
1001
1002 if (copy_from_user
1003 (&usr_config, (void *)arg,
1004 sizeof(usr_config))) {
1005 rc = -EFAULT;
1006 break;
1007 }
1008
1009 audio->wma_config = usr_config;
1010 rc = 0;
1011 break;
1012 }
1013 case AUDIO_GET_PCM_CONFIG:{
1014 struct msm_audio_pcm_config config;
1015 config.pcm_feedback = audio->pcm_feedback;
1016 config.buffer_count = PCM_BUF_MAX_COUNT;
1017 config.buffer_size = PCM_BUFSZ_MIN;
1018 if (copy_to_user((void *)arg, &config,
1019 sizeof(config)))
1020 rc = -EFAULT;
1021 else
1022 rc = 0;
1023 break;
1024 }
1025 case AUDIO_SET_PCM_CONFIG:{
1026 struct msm_audio_pcm_config config;
1027 if (copy_from_user
1028 (&config, (void *)arg, sizeof(config))) {
1029 rc = -EFAULT;
1030 break;
1031 }
1032 if (config.pcm_feedback != audio->pcm_feedback) {
1033 MM_ERR("Not sufficient permission to"
1034 "change the playback mode\n");
1035 rc = -EACCES;
1036 break;
1037 }
1038 if ((config.buffer_count > PCM_BUF_MAX_COUNT) ||
1039 (config.buffer_count == 1))
1040 config.buffer_count = PCM_BUF_MAX_COUNT;
1041
1042 if (config.buffer_size < PCM_BUFSZ_MIN)
1043 config.buffer_size = PCM_BUFSZ_MIN;
1044
1045 /* Check if pcm feedback is required */
1046 if ((config.pcm_feedback) && (!audio->read_data)) {
1047 MM_DBG("allocate PCM buffer %d\n",
1048 config.buffer_count *
1049 config.buffer_size);
Sidipotu Ashok172c98b2012-06-26 17:58:29 +05301050 handle = ion_alloc(audio->client,
1051 (config.buffer_size *
1052 config.buffer_count),
Hanumant Singh7d72bad2012-08-29 18:39:44 -07001053 SZ_4K, ION_HEAP(ION_AUDIO_HEAP_ID), 0);
Sidipotu Ashok172c98b2012-06-26 17:58:29 +05301054 if (IS_ERR_OR_NULL(handle)) {
1055 MM_ERR("Unable to alloc I/P buffs\n");
1056 audio->input_buff_handle = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001057 rc = -ENOMEM;
1058 break;
1059 }
Sidipotu Ashok172c98b2012-06-26 17:58:29 +05301060
1061 audio->input_buff_handle = handle;
1062
1063 rc = ion_phys(audio->client ,
1064 handle, &addr, &len);
1065 if (rc) {
1066 MM_ERR("Invalid phy: %x sz: %x\n",
1067 (unsigned int) addr,
1068 (unsigned int) len);
1069 ion_free(audio->client, handle);
1070 audio->input_buff_handle = NULL;
1071 rc = -ENOMEM;
1072 break;
1073 } else {
1074 MM_INFO("Got valid phy: %x sz: %x\n",
1075 (unsigned int) audio->read_phys,
1076 (unsigned int) len);
1077 }
1078 audio->read_phys = (int32_t)addr;
1079
1080 rc = ion_handle_get_flags(audio->client,
1081 handle, &ionflag);
1082 if (rc) {
1083 MM_ERR("could not get flags\n");
1084 ion_free(audio->client, handle);
1085 audio->input_buff_handle = NULL;
1086 rc = -ENOMEM;
1087 break;
1088 }
1089
1090 audio->map_v_read = ion_map_kernel(
Mitchel Humpherys911b4b72012-09-12 14:42:50 -07001091 audio->client, handle);
Santosh Mardi0be3b8e2011-07-06 10:00:21 +05301092 if (IS_ERR(audio->map_v_read)) {
1093 MM_ERR("map of read buf failed\n");
Sidipotu Ashok172c98b2012-06-26 17:58:29 +05301094 ion_free(audio->client, handle);
1095 audio->input_buff_handle = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001096 rc = -ENOMEM;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001097 } else {
1098 uint8_t index;
1099 uint32_t offset = 0;
Santosh Mardi0be3b8e2011-07-06 10:00:21 +05301100 audio->read_data =
Laura Abbott35111d32012-04-27 18:41:48 -07001101 audio->map_v_read;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001102 audio->buf_refresh = 0;
1103 audio->pcm_buf_count =
1104 config.buffer_count;
1105 audio->read_next = 0;
1106 audio->fill_next = 0;
1107
1108 for (index = 0;
1109 index < config.buffer_count;
1110 index++) {
1111 audio->in[index].data =
1112 audio->read_data + offset;
1113 audio->in[index].addr =
1114 audio->read_phys + offset;
1115 audio->in[index].size =
1116 config.buffer_size;
1117 audio->in[index].used = 0;
1118 offset += config.buffer_size;
1119 }
1120 MM_DBG("read buf: phy addr \
1121 0x%08x kernel addr 0x%08x\n",
1122 audio->read_phys,
1123 (int)audio->read_data);
1124 rc = 0;
1125 }
1126 } else {
1127 rc = 0;
1128 }
1129 break;
1130 }
1131 case AUDIO_PAUSE:
1132 MM_DBG("AUDIO_PAUSE %ld\n", arg);
1133 rc = audpp_pause(audio->dec_id, (int) arg);
1134 break;
1135 default:
1136 rc = -EINVAL;
1137 }
1138 mutex_unlock(&audio->lock);
1139 return rc;
1140}
1141
1142/* Only useful in tunnel-mode */
Sidipotu Ashok172c98b2012-06-26 17:58:29 +05301143static int audio_fsync(struct file *file, loff_t a, loff_t b,
1144 int datasync)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001145{
1146 struct audio *audio = file->private_data;
1147 struct buffer *frame;
1148 int rc = 0;
1149
1150 MM_DBG("\n"); /* Macro prints the file name and function */
1151
1152 if (!audio->running || audio->pcm_feedback) {
1153 rc = -EINVAL;
1154 goto done_nolock;
1155 }
1156
1157 mutex_lock(&audio->write_lock);
1158
1159 rc = wait_event_interruptible(audio->write_wait,
1160 (!audio->out[0].used &&
1161 !audio->out[1].used &&
1162 audio->out_needed) || audio->wflush);
1163
1164 if (rc < 0)
1165 goto done;
1166 else if (audio->wflush) {
1167 rc = -EBUSY;
1168 goto done;
1169 }
1170
1171 if (audio->reserved) {
1172 MM_DBG("send reserved byte\n");
1173 frame = audio->out + audio->out_tail;
1174 ((char *) frame->data)[0] = audio->rsv_byte;
1175 ((char *) frame->data)[1] = 0;
1176 frame->used = 2;
1177 audplay_send_data(audio, 0);
1178
1179 rc = wait_event_interruptible(audio->write_wait,
1180 (!audio->out[0].used &&
1181 !audio->out[1].used &&
1182 audio->out_needed) || audio->wflush);
1183
1184 if (rc < 0)
1185 goto done;
1186 else if (audio->wflush) {
1187 rc = -EBUSY;
1188 goto done;
1189 }
1190 }
1191
1192 /* pcm dmamiss message is sent continously
1193 * when decoder is starved so no race
1194 * condition concern
1195 */
1196 audio->teos = 0;
1197
1198 rc = wait_event_interruptible(audio->write_wait,
1199 audio->teos || audio->wflush);
1200
1201 if (audio->wflush)
1202 rc = -EBUSY;
1203
1204done:
1205 mutex_unlock(&audio->write_lock);
1206done_nolock:
1207 return rc;
1208}
1209
1210static ssize_t audio_read(struct file *file, char __user *buf, size_t count,
1211 loff_t *pos)
1212{
1213 struct audio *audio = file->private_data;
1214 const char __user *start = buf;
1215 int rc = 0;
1216
1217 if (!audio->pcm_feedback)
1218 return 0; /* PCM feedback is not enabled. Nothing to read */
1219
1220 mutex_lock(&audio->read_lock);
1221 MM_DBG("%d \n", count);
1222 while (count > 0) {
1223 rc = wait_event_interruptible(audio->read_wait,
1224 (audio->in[audio->read_next].used > 0) ||
1225 (audio->stopped) || (audio->rflush));
1226
1227 if (rc < 0)
1228 break;
1229
1230 if (audio->stopped || audio->rflush) {
1231 rc = -EBUSY;
1232 break;
1233 }
1234
1235 if (count < audio->in[audio->read_next].used) {
1236 /* Read must happen in frame boundary. Since driver
1237 does not know frame size, read count must be greater
1238 or equal to size of PCM samples */
1239 MM_DBG("audio_read: no partial frame done reading\n");
1240 break;
1241 } else {
1242 MM_DBG("audio_read: read from in[%d]\n",
1243 audio->read_next);
1244 /* order reads from the output buffer */
1245 rmb();
1246 if (copy_to_user
1247 (buf, audio->in[audio->read_next].data,
1248 audio->in[audio->read_next].used)) {
1249 MM_ERR("invalid addr %x \n", (unsigned int)buf);
1250 rc = -EFAULT;
1251 break;
1252 }
1253 count -= audio->in[audio->read_next].used;
1254 buf += audio->in[audio->read_next].used;
1255 audio->in[audio->read_next].used = 0;
1256 if ((++audio->read_next) == audio->pcm_buf_count)
1257 audio->read_next = 0;
1258 break; /* Force to exit while loop
1259 * to prevent output thread
1260 * sleep too long if data is
1261 * not ready at this moment.
1262 */
1263 }
1264 }
1265
1266 /* don't feed output buffer to HW decoder during flushing
1267 * buffer refresh command will be sent once flush completes
1268 * send buf refresh command here can confuse HW decoder
1269 */
1270 if (audio->buf_refresh && !audio->rflush) {
1271 audio->buf_refresh = 0;
1272 MM_DBG("kick start pcm feedback again\n");
1273 audplay_buffer_refresh(audio);
1274 }
1275
1276 mutex_unlock(&audio->read_lock);
1277
1278 if (buf > start)
1279 rc = buf - start;
1280
1281 MM_DBG("read %d bytes\n", rc);
1282 return rc;
1283}
1284
1285static int audwma_process_eos(struct audio *audio,
1286 const char __user *buf_start, unsigned short mfield_size)
1287{
1288 int rc = 0;
1289 struct buffer *frame;
1290 char *buf_ptr;
1291
1292 if (audio->reserved) {
1293 MM_DBG("flush reserve byte\n");
1294 frame = audio->out + audio->out_head;
1295 buf_ptr = frame->data;
1296 rc = wait_event_interruptible(audio->write_wait,
1297 (frame->used == 0)
1298 || (audio->stopped)
1299 || (audio->wflush));
1300 if (rc < 0)
1301 goto done;
1302 if (audio->stopped || audio->wflush) {
1303 rc = -EBUSY;
1304 goto done;
1305 }
1306
1307 buf_ptr[0] = audio->rsv_byte;
1308 buf_ptr[1] = 0;
1309 audio->out_head ^= 1;
1310 frame->mfield_sz = 0;
1311 frame->used = 2;
1312 audio->reserved = 0;
1313 audplay_send_data(audio, 0);
1314 }
1315
1316 frame = audio->out + audio->out_head;
1317
1318 rc = wait_event_interruptible(audio->write_wait,
1319 (audio->out_needed &&
1320 audio->out[0].used == 0 &&
1321 audio->out[1].used == 0)
1322 || (audio->stopped)
1323 || (audio->wflush));
1324
1325 if (rc < 0)
1326 goto done;
1327 if (audio->stopped || audio->wflush) {
1328 rc = -EBUSY;
1329 goto done;
1330 }
1331
1332 if (copy_from_user(frame->data, buf_start, mfield_size)) {
1333 rc = -EFAULT;
1334 goto done;
1335 }
1336
1337 frame->mfield_sz = mfield_size;
1338 audio->out_head ^= 1;
1339 frame->used = mfield_size;
1340 audplay_send_data(audio, 0);
1341done:
1342 return rc;
1343}
1344
1345static ssize_t audio_write(struct file *file, const char __user *buf,
1346 size_t count, loff_t *pos)
1347{
1348 struct audio *audio = file->private_data;
1349 const char __user *start = buf;
1350 struct buffer *frame;
1351 size_t xfer;
1352 char *cpy_ptr;
1353 int rc = 0, eos_condition = AUDWMA_EOS_NONE;
1354 unsigned dsize;
1355 unsigned short mfield_size = 0;
1356
1357 MM_DBG("cnt=%d\n", count);
1358
1359 mutex_lock(&audio->write_lock);
1360 while (count > 0) {
1361 frame = audio->out + audio->out_head;
1362 cpy_ptr = frame->data;
1363 dsize = 0;
1364 rc = wait_event_interruptible(audio->write_wait,
1365 (frame->used == 0)
1366 || (audio->stopped)
1367 || (audio->wflush));
1368 if (rc < 0)
1369 break;
1370 if (audio->stopped || audio->wflush) {
1371 rc = -EBUSY;
1372 break;
1373 }
1374 if (audio->mfield) {
1375 if (buf == start) {
1376 /* Processing beginning of user buffer */
1377 if (__get_user(mfield_size,
1378 (unsigned short __user *) buf)) {
1379 rc = -EFAULT;
1380 break;
1381 } else if (mfield_size > count) {
1382 rc = -EINVAL;
1383 break;
1384 }
1385 MM_DBG("audio_write: mf offset_val %x\n",
1386 mfield_size);
1387 if (copy_from_user(cpy_ptr, buf, mfield_size)) {
1388 rc = -EFAULT;
1389 break;
1390 }
1391 /* Check if EOS flag is set and buffer has
1392 * contains just meta field
1393 */
1394 if (cpy_ptr[AUDWMA_EOS_FLG_OFFSET] &
1395 AUDWMA_EOS_FLG_MASK) {
1396 MM_DBG("audio_write: EOS SET\n");
1397 eos_condition = AUDWMA_EOS_SET;
1398 if (mfield_size == count) {
1399 buf += mfield_size;
1400 break;
1401 } else
1402 cpy_ptr[AUDWMA_EOS_FLG_OFFSET]
1403 &= ~AUDWMA_EOS_FLG_MASK;
1404 }
1405 cpy_ptr += mfield_size;
1406 count -= mfield_size;
1407 dsize += mfield_size;
1408 buf += mfield_size;
1409 } else {
1410 mfield_size = 0;
1411 MM_DBG("audio_write: continuous buffer\n");
1412 }
1413 frame->mfield_sz = mfield_size;
1414 }
1415
1416 if (audio->reserved) {
1417 MM_DBG("append reserved byte %x\n", audio->rsv_byte);
1418 *cpy_ptr = audio->rsv_byte;
1419 xfer = (count > ((frame->size - mfield_size) - 1)) ?
1420 (frame->size - mfield_size) - 1 : count;
1421 cpy_ptr++;
1422 dsize += 1;
1423 audio->reserved = 0;
1424 } else
1425 xfer = (count > (frame->size - mfield_size)) ?
1426 (frame->size - mfield_size) : count;
1427
1428 if (copy_from_user(cpy_ptr, buf, xfer)) {
1429 rc = -EFAULT;
1430 break;
1431 }
1432
1433 dsize += xfer;
1434 if (dsize & 1) {
1435 audio->rsv_byte = ((char *) frame->data)[dsize - 1];
1436 MM_DBG("odd length buf reserve last byte %x\n",
1437 audio->rsv_byte);
1438 audio->reserved = 1;
1439 dsize--;
1440 }
1441 count -= xfer;
1442 buf += xfer;
1443
1444 if (dsize > 0) {
1445 audio->out_head ^= 1;
1446 frame->used = dsize;
1447 audplay_send_data(audio, 0);
1448 }
1449 }
1450 if (eos_condition == AUDWMA_EOS_SET)
1451 rc = audwma_process_eos(audio, start, mfield_size);
1452 mutex_unlock(&audio->write_lock);
1453 if (!rc) {
1454 if (buf > start)
1455 return buf - start;
1456 }
1457 return rc;
1458}
1459
1460static int audio_release(struct inode *inode, struct file *file)
1461{
1462 struct audio *audio = file->private_data;
1463
1464 MM_INFO("audio instance 0x%08x freeing\n", (int)audio);
1465 mutex_lock(&audio->lock);
1466 audio_disable(audio);
1467 if (audio->rmt_resource_released == 0)
1468 rmt_put_resource(audio);
1469 audio_flush(audio);
1470 audio_flush_pcm_buf(audio);
1471 msm_adsp_put(audio->audplay);
1472 audpp_adec_free(audio->dec_id);
1473#ifdef CONFIG_HAS_EARLYSUSPEND
1474 unregister_early_suspend(&audio->suspend_ctl.node);
1475#endif
1476 audio->event_abort = 1;
1477 wake_up(&audio->event_wait);
1478 audwma_reset_event_queue(audio);
Sidipotu Ashok172c98b2012-06-26 17:58:29 +05301479 ion_unmap_kernel(audio->client, audio->output_buff_handle);
1480 ion_free(audio->client, audio->output_buff_handle);
1481 if (audio->input_buff_handle != NULL) {
1482 ion_unmap_kernel(audio->client, audio->input_buff_handle);
1483 ion_free(audio->client, audio->input_buff_handle);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001484 }
Sidipotu Ashok172c98b2012-06-26 17:58:29 +05301485 ion_client_destroy(audio->client);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001486 mutex_unlock(&audio->lock);
1487#ifdef CONFIG_DEBUG_FS
1488 if (audio->dentry)
1489 debugfs_remove(audio->dentry);
1490#endif
1491 kfree(audio);
1492 return 0;
1493}
1494
1495#ifdef CONFIG_HAS_EARLYSUSPEND
1496static void audwma_post_event(struct audio *audio, int type,
1497 union msm_audio_event_payload payload)
1498{
1499 struct audwma_event *e_node = NULL;
1500 unsigned long flags;
1501
1502 spin_lock_irqsave(&audio->event_queue_lock, flags);
1503
1504 if (!list_empty(&audio->free_event_queue)) {
1505 e_node = list_first_entry(&audio->free_event_queue,
1506 struct audwma_event, list);
1507 list_del(&e_node->list);
1508 } else {
1509 e_node = kmalloc(sizeof(struct audwma_event), GFP_ATOMIC);
1510 if (!e_node) {
1511 MM_ERR("No mem to post event %d\n", type);
1512 spin_unlock_irqrestore(&audio->event_queue_lock, flags);
1513 return;
1514 }
1515 }
1516
1517 e_node->event_type = type;
1518 e_node->payload = payload;
1519
1520 list_add_tail(&e_node->list, &audio->event_queue);
1521 spin_unlock_irqrestore(&audio->event_queue_lock, flags);
1522 wake_up(&audio->event_wait);
1523}
1524
1525static void audwma_suspend(struct early_suspend *h)
1526{
1527 struct audwma_suspend_ctl *ctl =
1528 container_of(h, struct audwma_suspend_ctl, node);
1529 union msm_audio_event_payload payload;
1530
1531 MM_DBG("\n"); /* Macro prints the file name and function */
1532 audwma_post_event(ctl->audio, AUDIO_EVENT_SUSPEND, payload);
1533}
1534
1535static void audwma_resume(struct early_suspend *h)
1536{
1537 struct audwma_suspend_ctl *ctl =
1538 container_of(h, struct audwma_suspend_ctl, node);
1539 union msm_audio_event_payload payload;
1540
1541 MM_DBG("\n"); /* Macro prints the file name and function */
1542 audwma_post_event(ctl->audio, AUDIO_EVENT_RESUME, payload);
1543}
1544#endif
1545
1546#ifdef CONFIG_DEBUG_FS
1547static ssize_t audwma_debug_open(struct inode *inode, struct file *file)
1548{
1549 file->private_data = inode->i_private;
1550 return 0;
1551}
1552
1553static ssize_t audwma_debug_read(struct file *file, char __user *buf,
1554 size_t count, loff_t *ppos)
1555{
1556 const int debug_bufmax = 4096;
1557 static char buffer[4096];
1558 int n = 0, i;
1559 struct audio *audio = file->private_data;
1560
1561 mutex_lock(&audio->lock);
1562 n = scnprintf(buffer, debug_bufmax, "opened %d\n", audio->opened);
1563 n += scnprintf(buffer + n, debug_bufmax - n,
1564 "enabled %d\n", audio->enabled);
1565 n += scnprintf(buffer + n, debug_bufmax - n,
1566 "stopped %d\n", audio->stopped);
1567 n += scnprintf(buffer + n, debug_bufmax - n,
1568 "pcm_feedback %d\n", audio->pcm_feedback);
1569 n += scnprintf(buffer + n, debug_bufmax - n,
1570 "out_buf_sz %d\n", audio->out[0].size);
1571 n += scnprintf(buffer + n, debug_bufmax - n,
1572 "pcm_buf_count %d \n", audio->pcm_buf_count);
1573 n += scnprintf(buffer + n, debug_bufmax - n,
1574 "pcm_buf_sz %d \n", audio->in[0].size);
1575 n += scnprintf(buffer + n, debug_bufmax - n,
1576 "volume %x \n", audio->vol_pan.volume);
1577 n += scnprintf(buffer + n, debug_bufmax - n,
1578 "sample rate %d \n", audio->out_sample_rate);
1579 n += scnprintf(buffer + n, debug_bufmax - n,
1580 "channel mode %d \n", audio->out_channel_mode);
1581 mutex_unlock(&audio->lock);
1582 /* Following variables are only useful for debugging when
1583 * when playback halts unexpectedly. Thus, no mutual exclusion
1584 * enforced
1585 */
1586 n += scnprintf(buffer + n, debug_bufmax - n,
1587 "wflush %d\n", audio->wflush);
1588 n += scnprintf(buffer + n, debug_bufmax - n,
1589 "rflush %d\n", audio->rflush);
1590 n += scnprintf(buffer + n, debug_bufmax - n,
1591 "running %d \n", audio->running);
1592 n += scnprintf(buffer + n, debug_bufmax - n,
1593 "dec state %d \n", audio->dec_state);
1594 n += scnprintf(buffer + n, debug_bufmax - n,
1595 "out_needed %d \n", audio->out_needed);
1596 n += scnprintf(buffer + n, debug_bufmax - n,
1597 "out_head %d \n", audio->out_head);
1598 n += scnprintf(buffer + n, debug_bufmax - n,
1599 "out_tail %d \n", audio->out_tail);
1600 n += scnprintf(buffer + n, debug_bufmax - n,
1601 "out[0].used %d \n", audio->out[0].used);
1602 n += scnprintf(buffer + n, debug_bufmax - n,
1603 "out[1].used %d \n", audio->out[1].used);
1604 n += scnprintf(buffer + n, debug_bufmax - n,
1605 "buffer_refresh %d \n", audio->buf_refresh);
1606 n += scnprintf(buffer + n, debug_bufmax - n,
1607 "read_next %d \n", audio->read_next);
1608 n += scnprintf(buffer + n, debug_bufmax - n,
1609 "fill_next %d \n", audio->fill_next);
1610 for (i = 0; i < audio->pcm_buf_count; i++)
1611 n += scnprintf(buffer + n, debug_bufmax - n,
1612 "in[%d].size %d \n", i, audio->in[i].used);
1613 buffer[n] = 0;
1614 return simple_read_from_buffer(buf, count, ppos, buffer, n);
1615}
1616
1617static const struct file_operations audwma_debug_fops = {
1618 .read = audwma_debug_read,
1619 .open = audwma_debug_open,
1620};
1621#endif
1622
1623static int audio_open(struct inode *inode, struct file *file)
1624{
1625 struct audio *audio = NULL;
1626 int rc, dec_attrb, decid, i;
Sidipotu Ashok172c98b2012-06-26 17:58:29 +05301627 unsigned mem_sz = DMASZ_MAX;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001628 struct audwma_event *e_node = NULL;
Sidipotu Ashok172c98b2012-06-26 17:58:29 +05301629 unsigned long ionflag = 0;
1630 ion_phys_addr_t addr = 0;
1631 struct ion_handle *handle = NULL;
1632 struct ion_client *client = NULL;
1633 int len = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001634#ifdef CONFIG_DEBUG_FS
1635 /* 4 bytes represents decoder number, 1 byte for terminate string */
1636 char name[sizeof "msm_wma_" + 5];
1637#endif
1638
1639 /* Allocate Mem for audio instance */
1640 audio = kzalloc(sizeof(struct audio), GFP_KERNEL);
1641 if (!audio) {
1642 MM_ERR("no memory to allocate audio instance \n");
1643 rc = -ENOMEM;
1644 goto done;
1645 }
1646 MM_INFO("audio instance 0x%08x created\n", (int)audio);
1647
1648 /* Allocate the decoder */
1649 dec_attrb = AUDDEC_DEC_WMA;
1650 if ((file->f_mode & FMODE_WRITE) &&
1651 (file->f_mode & FMODE_READ)) {
1652 dec_attrb |= MSM_AUD_MODE_NONTUNNEL;
1653 audio->pcm_feedback = NON_TUNNEL_MODE_PLAYBACK;
1654 } else if ((file->f_mode & FMODE_WRITE) &&
1655 !(file->f_mode & FMODE_READ)) {
1656 dec_attrb |= MSM_AUD_MODE_TUNNEL;
1657 audio->pcm_feedback = TUNNEL_MODE_PLAYBACK;
1658 } else {
1659 kfree(audio);
1660 rc = -EACCES;
1661 goto done;
1662 }
1663
1664 decid = audpp_adec_alloc(dec_attrb, &audio->module_name,
1665 &audio->queue_id);
1666
1667 if (decid < 0) {
1668 MM_ERR("No free decoder available, freeing instance 0x%08x\n",
1669 (int)audio);
1670 rc = -ENODEV;
1671 kfree(audio);
1672 goto done;
1673 }
1674 audio->dec_id = decid & MSM_AUD_DECODER_MASK;
1675
Sidipotu Ashok172c98b2012-06-26 17:58:29 +05301676 client = msm_ion_client_create(UINT_MAX, "Audio_WMA_Client");
1677 if (IS_ERR_OR_NULL(client)) {
1678 pr_err("Unable to create ION client\n");
1679 rc = -ENOMEM;
1680 goto client_create_error;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001681 }
Sidipotu Ashok172c98b2012-06-26 17:58:29 +05301682 audio->client = client;
1683
1684 handle = ion_alloc(client, mem_sz, SZ_4K,
Hanumant Singh7d72bad2012-08-29 18:39:44 -07001685 ION_HEAP(ION_AUDIO_HEAP_ID), 0);
Sidipotu Ashok172c98b2012-06-26 17:58:29 +05301686 if (IS_ERR_OR_NULL(handle)) {
1687 MM_ERR("Unable to create allocate O/P buffers\n");
1688 rc = -ENOMEM;
1689 goto output_buff_alloc_error;
1690 }
1691 audio->output_buff_handle = handle;
1692
1693 rc = ion_phys(client, handle, &addr, &len);
1694 if (rc) {
1695 MM_ERR("O/P buffers:Invalid phy: %x sz: %x\n",
1696 (unsigned int) addr, (unsigned int) len);
1697 goto output_buff_get_phys_error;
1698 } else {
1699 MM_INFO("O/P buffers:valid phy: %x sz: %x\n",
1700 (unsigned int) addr, (unsigned int) len);
1701 }
1702 audio->phys = (int32_t)addr;
1703
1704
1705 rc = ion_handle_get_flags(client, handle, &ionflag);
1706 if (rc) {
1707 MM_ERR("could not get flags for the handle\n");
1708 goto output_buff_get_flags_error;
1709 }
1710
Mitchel Humpherys911b4b72012-09-12 14:42:50 -07001711 audio->map_v_write = ion_map_kernel(client, handle);
Sidipotu Ashok172c98b2012-06-26 17:58:29 +05301712 if (IS_ERR(audio->map_v_write)) {
1713 MM_ERR("could not map write buffers\n");
1714 rc = -ENOMEM;
1715 goto output_buff_map_error;
1716 }
1717 audio->data = audio->map_v_write;
1718 MM_DBG("write buf: phy addr 0x%08x kernel addr 0x%08x\n",
1719 audio->phys, (int)audio->data);
1720
1721 audio->out_dma_sz = mem_sz;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001722
1723 if (audio->pcm_feedback == TUNNEL_MODE_PLAYBACK) {
1724 rc = audmgr_open(&audio->audmgr);
1725 if (rc) {
1726 MM_ERR("audmgr open failed, freeing instance \
1727 0x%08x\n", (int)audio);
1728 goto err;
1729 }
1730 }
1731
1732 rc = msm_adsp_get(audio->module_name, &audio->audplay,
1733 &audplay_adsp_ops_wma, audio);
1734 if (rc) {
1735 MM_ERR("failed to get %s module, freeing instance 0x%08x\n",
1736 audio->module_name, (int)audio);
1737 if (audio->pcm_feedback == TUNNEL_MODE_PLAYBACK)
1738 audmgr_close(&audio->audmgr);
1739 goto err;
1740 }
1741
1742 rc = rmt_get_resource(audio);
1743 if (rc) {
1744 MM_ERR("ADSP resources are not available for WMA session \
1745 0x%08x on decoder: %d\n", (int)audio, audio->dec_id);
1746 if (audio->pcm_feedback == TUNNEL_MODE_PLAYBACK)
1747 audmgr_close(&audio->audmgr);
1748 msm_adsp_put(audio->audplay);
1749 goto err;
1750 }
1751
Sidipotu Ashok172c98b2012-06-26 17:58:29 +05301752 audio->input_buff_handle = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001753 mutex_init(&audio->lock);
1754 mutex_init(&audio->write_lock);
1755 mutex_init(&audio->read_lock);
1756 mutex_init(&audio->get_event_lock);
1757 spin_lock_init(&audio->dsp_lock);
1758 init_waitqueue_head(&audio->write_wait);
1759 init_waitqueue_head(&audio->read_wait);
1760 INIT_LIST_HEAD(&audio->free_event_queue);
1761 INIT_LIST_HEAD(&audio->event_queue);
1762 init_waitqueue_head(&audio->wait);
1763 init_waitqueue_head(&audio->event_wait);
1764 spin_lock_init(&audio->event_queue_lock);
1765
1766 audio->out[0].data = audio->data + 0;
1767 audio->out[0].addr = audio->phys + 0;
1768 audio->out[0].size = audio->out_dma_sz >> 1;
1769
1770 audio->out[1].data = audio->data + audio->out[0].size;
1771 audio->out[1].addr = audio->phys + audio->out[0].size;
1772 audio->out[1].size = audio->out[0].size;
1773
1774 audio->wma_config.armdatareqthr = 1262;
1775 audio->wma_config.channelsdecoded = 2;
1776 audio->wma_config.wmabytespersec = 6003;
1777 audio->wma_config.wmasamplingfreq = 44100;
1778 audio->wma_config.wmaencoderopts = 31;
1779
1780 audio->out_sample_rate = 44100;
1781 audio->out_channel_mode = AUDPP_CMD_PCM_INTF_STEREO_V;
1782
1783 audio->vol_pan.volume = 0x2000;
1784
1785 audio_flush(audio);
1786
1787 file->private_data = audio;
1788 audio->opened = 1;
1789#ifdef CONFIG_DEBUG_FS
1790 snprintf(name, sizeof name, "msm_wma_%04x", audio->dec_id);
1791 audio->dentry = debugfs_create_file(name, S_IFREG | S_IRUGO,
1792 NULL, (void *) audio,
1793 &audwma_debug_fops);
1794
1795 if (IS_ERR(audio->dentry))
1796 MM_DBG("debugfs_create_file failed\n");
1797#endif
1798#ifdef CONFIG_HAS_EARLYSUSPEND
1799 audio->suspend_ctl.node.level = EARLY_SUSPEND_LEVEL_DISABLE_FB;
1800 audio->suspend_ctl.node.resume = audwma_resume;
1801 audio->suspend_ctl.node.suspend = audwma_suspend;
1802 audio->suspend_ctl.audio = audio;
1803 register_early_suspend(&audio->suspend_ctl.node);
1804#endif
1805 for (i = 0; i < AUDWMA_EVENT_NUM; i++) {
1806 e_node = kmalloc(sizeof(struct audwma_event), GFP_KERNEL);
1807 if (e_node)
1808 list_add_tail(&e_node->list, &audio->free_event_queue);
1809 else {
1810 MM_ERR("event pkt alloc failed\n");
1811 break;
1812 }
1813 }
1814done:
1815 return rc;
1816err:
Sidipotu Ashok172c98b2012-06-26 17:58:29 +05301817 ion_unmap_kernel(client, audio->output_buff_handle);
1818output_buff_map_error:
1819output_buff_get_phys_error:
1820output_buff_get_flags_error:
1821 ion_free(client, audio->output_buff_handle);
1822output_buff_alloc_error:
1823 ion_client_destroy(client);
1824client_create_error:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001825 audpp_adec_free(audio->dec_id);
1826 kfree(audio);
1827 return rc;
1828}
1829
1830static const struct file_operations audio_wma_fops = {
1831 .owner = THIS_MODULE,
1832 .open = audio_open,
1833 .release = audio_release,
1834 .read = audio_read,
1835 .write = audio_write,
1836 .unlocked_ioctl = audio_ioctl,
1837 .fsync = audio_fsync,
1838};
1839
1840struct miscdevice audio_wma_misc = {
1841 .minor = MISC_DYNAMIC_MINOR,
1842 .name = "msm_wma",
1843 .fops = &audio_wma_fops,
1844};
1845
1846static int __init audio_init(void)
1847{
1848 return misc_register(&audio_wma_misc);
1849}
1850
1851device_initcall(audio_init);