Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* sound/soc/msm/msm-pcm.h |
| 2 | * |
| 3 | * Copyright (C) 2008 Google, Inc. |
| 4 | * Copyright (C) 2008 HTC Corporation |
| 5 | * Copyright (c) 2008-2009, Code Aurora Forum. 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. |
| 14 | * |
| 15 | * See the GNU General Public License for more details. |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, you can find it at http://www.fsf.org. |
| 18 | */ |
| 19 | |
| 20 | #ifndef _MSM_PCM_H |
| 21 | #define _MSM_PCM_H |
| 22 | |
| 23 | |
| 24 | #include <mach/qdsp5/qdsp5audppcmdi.h> |
| 25 | #include <mach/qdsp5/qdsp5audppmsg.h> |
| 26 | #include <mach/qdsp5/qdsp5audreccmdi.h> |
| 27 | #include <mach/qdsp5/qdsp5audrecmsg.h> |
| 28 | #include <mach/qdsp5/qdsp5audpreproccmdi.h> |
| 29 | #include <mach/qdsp5/qdsp5audpreprocmsg.h> |
| 30 | |
| 31 | #include <../arch/arm/mach-msm/qdsp5/adsp.h> |
| 32 | #include <../arch/arm/mach-msm/qdsp5/audmgr.h> |
| 33 | |
| 34 | |
| 35 | #define FRAME_NUM (8) |
| 36 | #define FRAME_SIZE (2052 * 2) |
| 37 | #define MONO_DATA_SIZE (2048) |
| 38 | #define STEREO_DATA_SIZE (MONO_DATA_SIZE * 2) |
| 39 | #define CAPTURE_DMASZ (FRAME_SIZE * FRAME_NUM) |
| 40 | |
| 41 | #define BUFSZ (960 * 5) |
| 42 | #define PLAYBACK_DMASZ (BUFSZ * 2) |
| 43 | |
| 44 | #define MSM_PLAYBACK_DEFAULT_VOLUME 0 /* 0dB */ |
| 45 | #define MSM_PLAYBACK_DEFAULT_PAN 0 |
| 46 | |
| 47 | #define USE_FORMATS SNDRV_PCM_FMTBIT_S16_LE |
| 48 | #define USE_CHANNELS_MIN 1 |
| 49 | #define USE_CHANNELS_MAX 2 |
| 50 | /* Support unconventional sample rates 12000, 24000 as well */ |
| 51 | #define USE_RATE \ |
| 52 | (SNDRV_PCM_RATE_8000_48000 | SNDRV_PCM_RATE_KNOT) |
| 53 | #define USE_RATE_MIN 8000 |
| 54 | #define USE_RATE_MAX 48000 |
| 55 | #define MAX_BUFFER_PLAYBACK_SIZE \ |
| 56 | (4800*4) |
| 57 | /* 2048 frames (Mono), 1024 frames (Stereo) */ |
| 58 | #define CAPTURE_SIZE 4096 |
| 59 | #define MAX_BUFFER_CAPTURE_SIZE (4096*4) |
| 60 | #define MAX_PERIOD_SIZE BUFSZ |
| 61 | #define USE_PERIODS_MAX 1024 |
| 62 | #define USE_PERIODS_MIN 1 |
| 63 | |
| 64 | |
| 65 | #define MAX_DB (16) |
| 66 | #define MIN_DB (-50) |
| 67 | #define PCMPLAYBACK_DECODERID 5 |
| 68 | |
| 69 | /* 0xFFFFFFFF Indicates not to be used for audio data copy */ |
| 70 | #define BUF_INVALID_LEN 0xFFFFFFFF |
| 71 | |
| 72 | extern int copy_count; |
| 73 | extern int intcnt; |
| 74 | |
| 75 | struct msm_volume { |
| 76 | bool update; |
| 77 | int volume; /* Volume parameter, in dB Scale */ |
| 78 | int pan; |
| 79 | }; |
| 80 | |
| 81 | struct buffer { |
| 82 | void *data; |
| 83 | unsigned size; |
| 84 | unsigned used; |
| 85 | unsigned addr; |
| 86 | }; |
| 87 | |
| 88 | struct buffer_rec { |
| 89 | void *data; |
| 90 | unsigned int size; |
| 91 | unsigned int read; |
| 92 | unsigned int addr; |
| 93 | }; |
| 94 | |
| 95 | struct audio_locks { |
| 96 | struct mutex lock; |
| 97 | struct mutex write_lock; |
| 98 | struct mutex read_lock; |
| 99 | spinlock_t read_dsp_lock; |
| 100 | spinlock_t write_dsp_lock; |
| 101 | spinlock_t mixer_lock; |
| 102 | wait_queue_head_t read_wait; |
| 103 | wait_queue_head_t write_wait; |
| 104 | wait_queue_head_t eos_wait; |
| 105 | }; |
| 106 | |
| 107 | extern struct audio_locks the_locks; |
| 108 | |
| 109 | struct msm_audio_event_callbacks { |
| 110 | /* event is called from interrupt context when a message |
| 111 | * arrives from the DSP. |
| 112 | */ |
| 113 | void (*playback)(void *); |
| 114 | void (*capture)(void *); |
| 115 | }; |
| 116 | |
| 117 | |
| 118 | struct msm_audio { |
| 119 | struct buffer out[2]; |
| 120 | struct buffer_rec in[8]; |
| 121 | |
| 122 | uint8_t out_head; |
| 123 | uint8_t out_tail; |
| 124 | uint8_t out_needed; /* number of buffers the dsp is waiting for */ |
| 125 | atomic_t out_bytes; |
| 126 | |
| 127 | /* configuration to use on next enable */ |
| 128 | uint32_t out_sample_rate; |
| 129 | uint32_t out_channel_mode; |
| 130 | uint32_t out_weight; |
| 131 | uint32_t out_buffer_size; |
| 132 | |
| 133 | struct audmgr audmgr; |
| 134 | struct snd_pcm_substream *playback_substream; |
| 135 | struct snd_pcm_substream *capture_substream; |
| 136 | |
| 137 | /* data allocated for various buffers */ |
| 138 | char *data; |
| 139 | dma_addr_t phys; |
| 140 | |
| 141 | unsigned int pcm_size; |
| 142 | unsigned int pcm_count; |
| 143 | unsigned int pcm_irq_pos; /* IRQ position */ |
| 144 | unsigned int pcm_buf_pos; /* position in buffer */ |
| 145 | |
| 146 | struct msm_adsp_module *audpre; |
| 147 | struct msm_adsp_module *audrec; |
| 148 | |
| 149 | /* configuration to use on next enable */ |
| 150 | uint32_t samp_rate; |
| 151 | uint32_t channel_mode; |
| 152 | uint32_t buffer_size; /* 2048 for mono, 4096 for stereo */ |
| 153 | uint32_t type; /* 0 for PCM ,1 for AAC */ |
| 154 | uint32_t dsp_cnt; |
| 155 | uint32_t in_head; /* next buffer dsp will write */ |
| 156 | uint32_t in_tail; /* next buffer read() will read */ |
| 157 | uint32_t in_count; /* number of buffers available to read() */ |
| 158 | |
| 159 | unsigned short samp_rate_index; |
| 160 | |
| 161 | /* audpre settings */ |
| 162 | audpreproc_cmd_cfg_agc_params tx_agc_cfg; |
| 163 | audpreproc_cmd_cfg_ns_params ns_cfg; |
| 164 | /* For different sample rate, the coeff might be different. * |
| 165 | * All the coeff should be passed from user space */ |
| 166 | audpreproc_cmd_cfg_iir_tuning_filter_params iir_cfg; |
| 167 | |
| 168 | struct msm_audio_event_callbacks *ops; |
| 169 | |
| 170 | int dir; |
| 171 | int opened; |
| 172 | int enabled; |
| 173 | int running; |
| 174 | int stopped; /* set when stopped, cleared on flush */ |
| 175 | int eos_ack; |
| 176 | }; |
| 177 | |
| 178 | |
| 179 | |
| 180 | /* platform data */ |
| 181 | extern int audio_dsp_out_enable(struct msm_audio *prtd, int yes); |
| 182 | extern struct snd_soc_platform_driver msm_soc_platform; |
| 183 | |
| 184 | int audrec_encoder_config(struct msm_audio *prtd); |
| 185 | extern void alsa_get_dsp_frames(struct msm_audio *prtd); |
| 186 | extern int alsa_rec_dsp_enable(struct msm_audio *prtd, int enable); |
| 187 | extern int alsa_audrec_disable(struct msm_audio *prtd); |
| 188 | extern int alsa_audio_configure(struct msm_audio *prtd); |
| 189 | extern int alsa_audio_disable(struct msm_audio *prtd); |
| 190 | extern int alsa_adsp_configure(struct msm_audio *prtd); |
| 191 | extern int alsa_buffer_read(struct msm_audio *prtd, void __user *buf, |
| 192 | size_t count, loff_t *pos); |
| 193 | ssize_t alsa_send_buffer(struct msm_audio *prtd, const char __user *buf, |
| 194 | size_t count, loff_t *pos); |
| 195 | int msm_audio_volume_update(unsigned id, |
| 196 | int volume, int pan); |
| 197 | extern struct audio_locks the_locks; |
| 198 | extern struct msm_volume msm_vol_ctl; |
| 199 | |
| 200 | #endif /*_MSM_PCM_H*/ |