blob: fec7cf57027b740d81df06eeba0729d5150ce3db [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/*
2 * Copyright (C) 2008 Google, Inc.
3 * Copyright (C) 2008 HTC Corporation
4 * Copyright (c) 2008-2010, Code Aurora Forum. All rights reserved.
5 *
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 *
14 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, you can find it at http://www.fsf.org.
17 */
18
19#ifndef _MSM_PCM_H
20#define _MSM_PCM_H
21
22
23#include <mach/qdsp5v2/qdsp5audppcmdi.h>
24#include <mach/qdsp5v2/qdsp5audppmsg.h>
25#include <mach/qdsp5v2/qdsp5audplaycmdi.h>
26#include <mach/qdsp5v2/qdsp5audplaymsg.h>
27#include <mach/qdsp5v2/audpp.h>
28#include <mach/msm_adsp.h>
29#include <mach/qdsp5v2/qdsp5audreccmdi.h>
30#include <mach/qdsp5v2/qdsp5audrecmsg.h>
31#include <mach/qdsp5v2/audpreproc.h>
32
33
34#define FRAME_NUM (8)
35#define FRAME_SIZE (2052 * 2)
36#define MONO_DATA_SIZE (2048)
37#define STEREO_DATA_SIZE (MONO_DATA_SIZE * 2)
38#define CAPTURE_DMASZ (FRAME_SIZE * FRAME_NUM)
39
40#define BUFSZ (960 * 5)
41#define PLAYBACK_DMASZ (BUFSZ * 2)
42
43#define MSM_PLAYBACK_DEFAULT_VOLUME 0 /* 0dB */
44#define MSM_PLAYBACK_DEFAULT_PAN 0
45
46#define USE_FORMATS SNDRV_PCM_FMTBIT_S16_LE
47#define USE_CHANNELS_MIN 1
48#define USE_CHANNELS_MAX 2
49/* Support unconventional sample rates 12000, 24000 as well */
50#define USE_RATE \
51 (SNDRV_PCM_RATE_8000_48000 | SNDRV_PCM_RATE_KNOT)
52#define USE_RATE_MIN 8000
53#define USE_RATE_MAX 48000
54#define MAX_BUFFER_PLAYBACK_SIZE \
55 PLAYBACK_DMASZ
56/* 2048 frames (Mono), 1024 frames (Stereo) */
57#define CAPTURE_SIZE 4096
58#define MAX_BUFFER_CAPTURE_SIZE (4096*4)
59#define MAX_PERIOD_SIZE BUFSZ
60#define USE_PERIODS_MAX 1024
61#define USE_PERIODS_MIN 1
62
63
64#define MAX_DB (16)
65#define MIN_DB (-50)
66#define PCMPLAYBACK_DECODERID 5
67
68/* 0xFFFFFFFF Indicates not to be used for audio data copy */
69#define BUF_INVALID_LEN 0xFFFFFFFF
70#define EVENT_MSG_ID ((uint16_t)~0)
71
72#define AUDDEC_DEC_PCM 0
73/* Decoder status received from AUDPPTASK */
74#define AUDPP_DEC_STATUS_SLEEP 0
75#define AUDPP_DEC_STATUS_INIT 1
76#define AUDPP_DEC_STATUS_CFG 2
77#define AUDPP_DEC_STATUS_PLAY 3
78
79extern int copy_count;
80extern int intcnt;
81
82struct buffer {
83 void *data;
84 unsigned size;
85 unsigned used;
86 unsigned addr;
87};
88
89struct buffer_rec {
90 void *data;
91 unsigned int size;
92 unsigned int read;
93 unsigned int addr;
94};
95
96struct audio_locks {
97 struct mutex lock;
98 struct mutex write_lock;
99 struct mutex read_lock;
100 spinlock_t read_dsp_lock;
101 spinlock_t write_dsp_lock;
102 spinlock_t mixer_lock;
103 wait_queue_head_t read_wait;
104 wait_queue_head_t write_wait;
105 wait_queue_head_t wait;
106 wait_queue_head_t eos_wait;
107 wait_queue_head_t enable_wait;
108};
109
110extern struct audio_locks the_locks;
111
112struct msm_audio_event_callbacks {
113 /* event is called from interrupt context when a message
114 * arrives from the DSP.
115 */
116 void (*playback)(void *);
117 void (*capture)(void *);
118};
119
120
121struct msm_audio {
122 struct buffer out[2];
123 struct buffer_rec in[8];
124
125 uint8_t out_head;
126 uint8_t out_tail;
127 uint8_t out_needed; /* number of buffers the dsp is waiting for */
128 atomic_t out_bytes;
129
130 /* configuration to use on next enable */
131 uint32_t out_sample_rate;
132 uint32_t out_channel_mode;
133 uint32_t out_weight;
134 uint32_t out_buffer_size;
135
136 struct snd_pcm_substream *substream;
137
138 /* data allocated for various buffers */
139 char *data;
140 dma_addr_t phys;
141
142 unsigned int pcm_size;
143 unsigned int pcm_count;
144 unsigned int pcm_irq_pos; /* IRQ position */
145 unsigned int pcm_buf_pos; /* position in buffer */
146 uint16_t source; /* Encoding source bit mask */
147
148 struct msm_adsp_module *audpre;
149 struct msm_adsp_module *audrec;
150 struct msm_adsp_module *audplay;
151 enum msm_aud_decoder_state dec_state; /* Represents decoder state */
152
153 uint16_t session_id;
154 uint32_t out_bits; /* bits per sample */
155 const char *module_name;
156 unsigned queue_id;
157
158 /* configuration to use on next enable */
159 uint32_t samp_rate;
160 uint32_t channel_mode;
161 uint32_t buffer_size; /* 2048 for mono, 4096 for stereo */
162 uint32_t type; /* 0 for PCM ,1 for AAC */
163 uint32_t dsp_cnt;
164 uint32_t in_head; /* next buffer dsp will write */
165 uint32_t in_tail; /* next buffer read() will read */
166 uint32_t in_count; /* number of buffers available to read() */
167
168 unsigned short samp_rate_index;
169 uint32_t device_events; /* device events interested in */
170 int abort; /* set when error, like sample rate mismatch */
171
172 /* audpre settings */
173 /* For different sample rate, the coeff might be different. *
174 * All the coeff should be passed from user space */
175
176 struct msm_audio_event_callbacks *ops;
177
178 int dir;
179 int opened;
180 int enabled;
181 int running;
182 int stopped; /* set when stopped, cleared on flush */
183 int eos_ack;
184 int mmap_flag;
185 int period;
186 struct audpp_cmd_cfg_object_params_volume vol_pan;
187};
188
189
190
191/* platform data */
192extern int alsa_dsp_send_buffer(struct msm_audio *prtd,
193 unsigned idx, unsigned len);
194extern int audio_dsp_out_enable(struct msm_audio *prtd, int yes);
195extern struct snd_soc_platform_driver msm_soc_platform;
196
197extern int audrec_encoder_config(struct msm_audio *prtd);
198extern int alsa_audrec_disable(struct msm_audio *prtd);
199extern int alsa_audio_configure(struct msm_audio *prtd);
200extern int alsa_audio_disable(struct msm_audio *prtd);
201extern int alsa_buffer_read(struct msm_audio *prtd, void __user *buf,
202 size_t count, loff_t *pos);
203ssize_t alsa_send_buffer(struct msm_audio *prtd, const char __user *buf,
204 size_t count, loff_t *pos);
205extern struct msm_adsp_ops alsa_audrec_adsp_ops;
206extern int alsa_in_record_config(struct msm_audio *prtd, int enable);
207#endif /*_MSM_PCM_H*/