blob: c36d5a94054ecb7cb3f9a2cd485889ee76d1964d [file] [log] [blame]
Harmandeep Singhc35fa07d2012-05-31 07:08:59 -07001/*
Duy Truong790f06d2013-02-13 16:38:12 -08002 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
Harmandeep Singhc35fa07d2012-05-31 07:08:59 -07003 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 */
14#include <linux/module.h>
15#include <linux/fs.h>
16#include <linux/miscdevice.h>
17#include <linux/uaccess.h>
18#include <linux/sched.h>
19#include <linux/wait.h>
20#include <linux/dma-mapping.h>
21#include <linux/slab.h>
22#include <asm/atomic.h>
23#include <asm/ioctls.h>
24#include "audio_utils.h"
25
26void q6asm_in_cb(uint32_t opcode, uint32_t token,
27 uint32_t *payload, void *priv)
28{
29 struct q6audio_in * audio = (struct q6audio_in *)priv;
30 unsigned long flags;
31
32 pr_debug("%s:session id %d: opcode[0x%x]\n", __func__,
33 audio->ac->session, opcode);
34
35 spin_lock_irqsave(&audio->dsp_lock, flags);
36 switch (opcode) {
37 case ASM_DATA_EVENT_READ_DONE:
38 audio_in_get_dsp_frames(audio, token, payload);
39 break;
40 case ASM_DATA_EVENT_WRITE_DONE:
41 atomic_inc(&audio->in_count);
42 wake_up(&audio->write_wait);
43 break;
44 case ASM_DATA_CMDRSP_EOS:
45 audio->eos_rsp = 1;
46 wake_up(&audio->read_wait);
47 break;
48 case ASM_STREAM_CMDRSP_GET_ENCDEC_PARAM:
49 break;
50 case ASM_STREAM_CMDRSP_GET_PP_PARAMS:
51 break;
52 case ASM_SESSION_EVENT_TX_OVERFLOW:
53 pr_err("%s:session id %d: ASM_SESSION_EVENT_TX_OVERFLOW\n",
54 __func__, audio->ac->session);
55 break;
56 default:
57 pr_debug("%s:session id %d: Ignore opcode[0x%x]\n", __func__,
58 audio->ac->session, opcode);
59 break;
60 }
61 spin_unlock_irqrestore(&audio->dsp_lock, flags);
62}
63
64void audio_in_get_dsp_frames(/*struct q6audio_in *audio,*/void *aud,
65 uint32_t token, uint32_t *payload)
66{
67 struct q6audio_in *audio = (struct q6audio_in *)aud;
68 uint32_t index;
69
70 index = token;
71 pr_debug("%s:session id %d: index=%d nr frames=%d offset[%d]\n",
72 __func__, audio->ac->session, token, payload[7],
73 payload[3]);
74 pr_debug("%s:session id %d: timemsw=%d lsw=%d\n", __func__,
75 audio->ac->session, payload[4], payload[5]);
76 pr_debug("%s:session id %d: uflags=0x%8x uid=0x%8x\n", __func__,
77 audio->ac->session, payload[6], payload[8]);
78 pr_debug("%s:session id %d: enc frame size=0x%8x\n", __func__,
79 audio->ac->session, payload[2]);
80
81 audio->out_frame_info[index][0] = payload[7];
82 audio->out_frame_info[index][1] = payload[3];
83
84 /* statistics of read */
85 atomic_add(payload[2], &audio->in_bytes);
86 atomic_add(payload[7], &audio->in_samples);
87
88 if (atomic_read(&audio->out_count) <= audio->str_cfg.buffer_count) {
89 atomic_inc(&audio->out_count);
90 wake_up(&audio->read_wait);
91 }
92}