1 /* 2 ** Copyright 2008, The Android Open-Source Project 3 ** 4 ** Licensed under the Apache License, Version 2.0 (the "License"); 5 ** you may not use this file except in compliance with the License. 6 ** You may obtain a copy of the License at 7 ** 8 ** http://www.apache.org/licenses/LICENSE-2.0 9 ** 10 ** Unless required by applicable law or agreed to in writing, software 11 ** distributed under the License is distributed on an "AS IS" BASIS, 12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 ** See the License for the specific language governing permissions and 14 ** limitations under the License. 15 */ 16 17 #ifndef ANDROID_AUDIO_HARDWARE_H 18 #define ANDROID_AUDIO_HARDWARE_H 19 20 #include <stdint.h> 21 #include <sys/types.h> 22 23 #include <utils/threads.h> 24 #include <utils/SortedVector.h> 25 26 #include <hardware_legacy/AudioHardwareBase.h> 27 28 namespace android { 29 30 // ---------------------------------------------------------------------------- 31 // Kernel driver interface 32 // 33 /* Source (TX) devices */ 34 #define ADSP_AUDIO_DEVICE_ID_HANDSET_MIC 0x107ac8d 35 #define ADSP_AUDIO_DEVICE_ID_HEADSET_MIC 0x1081510 36 #define ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MIC 0x1081512 37 #define ADSP_AUDIO_DEVICE_ID_BT_SCO_MIC 0x1081518 38 #define ADSP_AUDIO_DEVICE_ID_TTY_HEADSET_MIC 0x108151b 39 #define ADSP_AUDIO_DEVICE_ID_I2S_MIC 0x1089bf3 40 41 /* Special loopback pseudo device to be paired with an RX device */ 42 /* with usage ADSP_AUDIO_DEVICE_USAGE_MIXED_PCM_LOOPBACK */ 43 #define ADSP_AUDIO_DEVICE_ID_MIXED_PCM_LOOPBACK_TX 0x1089bf2 44 45 /* Sink (RX) devices */ 46 #define ADSP_AUDIO_DEVICE_ID_HANDSET_SPKR 0x107ac88 47 #define ADSP_AUDIO_DEVICE_ID_HEADSET_SPKR_MONO 0x1081511 48 #define ADSP_AUDIO_DEVICE_ID_HEADSET_SPKR_STEREO 0x107ac8a 49 #define ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MONO 0x1081513 50 #define ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MONO_W_MONO_HEADSET 0x108c508 51 #define ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MONO_W_STEREO_HEADSET 0x108c894 52 #define ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_STEREO 0x1081514 53 #define ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_STEREO_W_MONO_HEADSET 0x108c895 54 #define ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_STEREO_W_STEREO_HEADSET 0x108c509 55 #define ADSP_AUDIO_DEVICE_ID_BT_SCO_SPKR 0x1081519 56 #define ADSP_AUDIO_DEVICE_ID_TTY_HEADSET_SPKR 0x108151c 57 #define ADSP_AUDIO_DEVICE_ID_I2S_SPKR 0x1089bf4 58 59 #define HANDSET_MIC ADSP_AUDIO_DEVICE_ID_HANDSET_MIC 60 #define HANDSET_SPKR ADSP_AUDIO_DEVICE_ID_HANDSET_SPKR 61 #define HEADSET_MIC ADSP_AUDIO_DEVICE_ID_HEADSET_MIC 62 #define HEADSET_SPKR_MONO ADSP_AUDIO_DEVICE_ID_HEADSET_SPKR_MONO 63 #define HEADSET_SPKR_STEREO ADSP_AUDIO_DEVICE_ID_HEADSET_SPKR_STEREO 64 #define SPKR_PHONE_MIC ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MIC 65 #define SPKR_PHONE_MONO ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MONO 66 #define SPKR_PHONE_STEREO ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_STEREO 67 #define BT_A2DP_SPKR ADSP_AUDIO_DEVICE_ID_BT_A2DP_SPKR 68 #define BT_SCO_MIC ADSP_AUDIO_DEVICE_ID_BT_SCO_MIC 69 #define BT_SCO_SPKR ADSP_AUDIO_DEVICE_ID_BT_SCO_SPKR 70 #define TTY_HEADSET_MIC ADSP_AUDIO_DEVICE_ID_TTY_HEADSET_MIC 71 #define TTY_HEADSET_SPKR ADSP_AUDIO_DEVICE_ID_TTY_HEADSET_SPKR 72 #define FM_HEADSET ADSP_AUDIO_DEVICE_ID_HEADSET_SPKR_STEREO 73 #define FM_SPKR ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MONO 74 #define SPKR_PHONE_HEADSET_STEREO ADSP_AUDIO_DEVICE_ID_SPKR_PHONE_MONO_W_MONO_HEADSET 75 76 #define ACDB_ID_HAC_HANDSET_MIC 107 77 #define ACDB_ID_HAC_HANDSET_SPKR 207 78 #define ACDB_ID_EXT_MIC_REC 307 79 #define ACDB_ID_HEADSET_PLAYBACK 407 80 #define ACDB_ID_HEADSET_RINGTONE_PLAYBACK 408 81 #define ACDB_ID_INT_MIC_REC 507 82 #define ACDB_ID_CAMCORDER 508 83 #define ACDB_ID_INT_MIC_VR 509 84 #define ACDB_ID_SPKR_PLAYBACK 607 85 #define ACDB_ID_ALT_SPKR_PLAYBACK 609 86 87 #define SAMP_RATE_INDX_8000 0 88 #define SAMP_RATE_INDX_11025 1 89 #define SAMP_RATE_INDX_12000 2 90 #define SAMP_RATE_INDX_16000 3 91 #define SAMP_RATE_INDX_22050 4 92 #define SAMP_RATE_INDX_24000 5 93 #define SAMP_RATE_INDX_32000 6 94 #define SAMP_RATE_INDX_44100 7 95 #define SAMP_RATE_INDX_48000 8 96 97 #define EQ_MAX_BAND_NUM 12 98 99 #define ADRC_ENABLE 0x0001 100 #define ADRC_DISABLE 0x0000 101 #define EQ_ENABLE 0x0002 102 #define EQ_DISABLE 0x0000 103 #define RX_IIR_ENABLE 0x0004 104 #define RX_IIR_DISABLE 0x0000 105 106 #define KEY_A1026_VR_MODE "vr_mode" 107 108 #define MOD_PLAY 1 109 #define MOD_REC 2 110 111 struct msm_bt_endpoint { 112 int tx; 113 int rx; 114 char name[64]; 115 }; 116 117 struct eq_filter_type { 118 int16_t gain; 119 uint16_t freq; 120 uint16_t type; 121 uint16_t qf; 122 }; 123 124 struct eqalizer { 125 uint16_t bands; 126 uint16_t params[132]; 127 }; 128 129 struct rx_iir_filter { 130 uint16_t num_bands; 131 uint16_t iir_params[48]; 132 }; 133 134 struct msm_audio_config { 135 uint32_t buffer_size; 136 uint32_t buffer_count; 137 uint32_t channel_count; 138 uint32_t sample_rate; 139 uint32_t codec_type; 140 uint32_t unused[3]; 141 }; 142 143 struct msm_mute_info { 144 uint32_t mute; 145 uint32_t path; 146 }; 147 148 #define CODEC_TYPE_PCM 0 149 #define PCM_FILL_BUFFER_COUNT 1 150 #define AUDIO_HW_NUM_OUT_BUF 4 // Number of buffers in audio driver for output 151 // TODO: determine actual audio DSP and hardware latency 152 #define AUDIO_HW_OUT_LATENCY_MS 0 // Additionnal latency introduced by audio DSP and hardware in ms 153 #define AUDIO_HW_OUT_SAMPLERATE 44100 // Default audio output sample rate 154 #define AUDIO_HW_OUT_CHANNELS (AudioSystem::CHANNEL_OUT_STEREO) // Default audio output channel mask 155 #define AUDIO_HW_OUT_FORMAT (AudioSystem::PCM_16_BIT) // Default audio output sample format 156 #define AUDIO_HW_OUT_BUFSZ 3072 // Default audio output buffer size 157 158 #define AUDIO_HW_IN_SAMPLERATE 8000 // Default audio input sample rate 159 #define AUDIO_HW_IN_CHANNELS (AudioSystem::CHANNEL_IN_MONO) // Default audio input channel mask 160 #define AUDIO_HW_IN_FORMAT (AudioSystem::PCM_16_BIT) // Default audio input sample format 161 #define AUDIO_HW_IN_BUFSZ 256 // Default audio input buffer size 162 163 #define VOICE_VOLUME_MAX 5 // Maximum voice volume 164 // ---------------------------------------------------------------------------- 165 166 167 class AudioHardware : public AudioHardwareBase 168 { 169 class AudioStreamOutMSM72xx; 170 class AudioStreamInMSM72xx; 171 172 public: 173 AudioHardware(); 174 virtual ~AudioHardware(); 175 virtual status_t initCheck(); 176 177 virtual status_t setVoiceVolume(float volume); 178 virtual status_t setMasterVolume(float volume); 179 180 virtual status_t setMode(int mode); 181 182 // mic mute 183 virtual status_t setMicMute(bool state); 184 virtual status_t getMicMute(bool* state); 185 186 virtual status_t setParameters(const String8& keyValuePairs); 187 virtual String8 getParameters(const String8& keys); 188 189 // create I/O streams 190 virtual AudioStreamOut* openOutputStream( 191 uint32_t devices, 192 int *format=0, 193 uint32_t *channels=0, 194 uint32_t *sampleRate=0, 195 status_t *status=0); 196 197 virtual AudioStreamIn* openInputStream( 198 199 uint32_t devices, 200 int *format, 201 uint32_t *channels, 202 uint32_t *sampleRate, 203 status_t *status, 204 AudioSystem::audio_in_acoustics acoustics); 205 206 virtual void closeOutputStream(AudioStreamOut* out); 207 virtual void closeInputStream(AudioStreamIn* in); 208 209 virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount); 210 211 void clearCurDevice() { mCurSndDevice = -1; } 212 213 protected: 214 virtual status_t dump(int fd, const Vector<String16>& args); 215 216 private: 217 218 status_t doAudioRouteOrMute(uint32_t device); 219 status_t setMicMute_nosync(bool state); 220 status_t checkMicMute(); 221 status_t dumpInternals(int fd, const Vector<String16>& args); 222 uint32_t getInputSampleRate(uint32_t sampleRate); 223 bool checkOutputStandby(); 224 status_t get_mMode(); 225 status_t get_mRoutes(); 226 status_t set_mRecordState(bool onoff); 227 status_t doA1026_init(); 228 status_t get_snd_dev(); 229 status_t get_batt_temp(int *batt_temp); 230 status_t doAudience_A1026_Control(int Mode, bool Record, uint32_t Routes); 231 status_t doRouting(); 232 status_t updateACDB(); 233 uint32_t getACDB(int mode, int device); 234 AudioStreamInMSM72xx* getActiveInput_l(); 235 status_t do_tpa2018_control(int mode); 236 size_t getBufferSize(uint32_t sampleRate, int channelCount); 237 238 class AudioStreamOutMSM72xx : public AudioStreamOut { 239 public: 240 AudioStreamOutMSM72xx(); 241 virtual ~AudioStreamOutMSM72xx(); 242 status_t set(AudioHardware* mHardware, 243 uint32_t devices, 244 int *pFormat, 245 uint32_t *pChannels, 246 uint32_t *pRate); 247 virtual uint32_t sampleRate() const { return mSampleRate; } 248 // must be 32-bit aligned 249 virtual size_t bufferSize() const { return mBufferSize; } 250 virtual uint32_t channels() const { return mChannels; } 251 virtual int format() const { return AUDIO_HW_OUT_FORMAT; } 252 virtual uint32_t latency() const { return (1000*AUDIO_HW_NUM_OUT_BUF*(bufferSize()/frameSize()))/sampleRate()+AUDIO_HW_OUT_LATENCY_MS; } 253 virtual status_t setVolume(float left, float right) { return INVALID_OPERATION; } 254 virtual ssize_t write(const void* buffer, size_t bytes); 255 virtual status_t standby(); 256 virtual status_t dump(int fd, const Vector<String16>& args); 257 bool checkStandby(); 258 virtual status_t setParameters(const String8& keyValuePairs); 259 virtual String8 getParameters(const String8& keys); 260 uint32_t devices() { return mDevices; } 261 virtual status_t getRenderPosition(uint32_t *dspFrames); 262 263 private: 264 AudioHardware* mHardware; 265 int mFd; 266 int mStartCount; 267 int mRetryCount; 268 bool mStandby; 269 uint32_t mDevices; 270 uint32_t mChannels; 271 uint32_t mSampleRate; 272 size_t mBufferSize; 273 }; 274 275 class AudioStreamInMSM72xx : public AudioStreamIn { 276 public: 277 enum input_state { 278 AUDIO_INPUT_CLOSED, 279 AUDIO_INPUT_OPENED, 280 AUDIO_INPUT_STARTED 281 }; 282 283 AudioStreamInMSM72xx(); 284 virtual ~AudioStreamInMSM72xx(); 285 status_t set(AudioHardware* mHardware, 286 uint32_t devices, 287 int *pFormat, 288 uint32_t *pChannels, 289 uint32_t *pRate, 290 AudioSystem::audio_in_acoustics acoustics); 291 virtual size_t bufferSize() const { return mBufferSize; } 292 virtual uint32_t channels() const { return mChannels; } 293 virtual int format() const { return mFormat; } 294 virtual uint32_t sampleRate() const { return mSampleRate; } 295 virtual status_t setGain(float gain) { return INVALID_OPERATION; } 296 virtual ssize_t read(void* buffer, ssize_t bytes); 297 virtual status_t dump(int fd, const Vector<String16>& args); 298 virtual status_t standby(); 299 virtual status_t setParameters(const String8& keyValuePairs); 300 virtual String8 getParameters(const String8& keys); 301 virtual unsigned int getInputFramesLost() const { return 0; } 302 uint32_t devices() { return mDevices; } 303 int state() const { return mState; } 304 305 private: 306 AudioHardware* mHardware; 307 int mFd; 308 int mState; 309 int mRetryCount; 310 int mFormat; 311 uint32_t mChannels; 312 uint32_t mSampleRate; 313 size_t mBufferSize; 314 AudioSystem::audio_in_acoustics mAcoustics; 315 uint32_t mDevices; 316 }; 317 318 enum tty_modes { 319 TTY_MODE_OFF, 320 TTY_MODE_FULL, 321 TTY_MODE_VCO, 322 TTY_MODE_HCO 323 }; 324 325 static const uint32_t inputSamplingRates[]; 326 Mutex mA1026Lock; 327 bool mA1026Init; 328 bool mRecordState; 329 bool mInit; 330 bool mMicMute; 331 bool mBluetoothNrec; 332 bool mHACSetting; 333 uint32_t mBluetoothIdTx; 334 uint32_t mBluetoothIdRx; 335 AudioStreamOutMSM72xx* mOutput; 336 SortedVector <AudioStreamInMSM72xx*> mInputs; 337 338 msm_bt_endpoint *mBTEndpoints; 339 int mNumBTEndpoints; 340 int mCurSndDevice; 341 int mNoiseSuppressionState; 342 uint32_t mVoiceVolume; 343 344 friend class AudioStreamInMSM72xx; 345 Mutex mLock; 346 uint32_t mRoutes[AudioSystem::NUM_MODES]; 347 int mTTYMode; 348 }; 349 350 // ---------------------------------------------------------------------------- 351 352 }; // namespace android 353 354 #endif // ANDROID_AUDIO_HARDWARE_MSM72XX_H 355