| 1 | /*************************************************************************** |
|---|
| 2 | * (c)2004-2011 Broadcom Corporation |
|---|
| 3 | * |
|---|
| 4 | * This program is the proprietary software of Broadcom Corporation and/or its licensors, |
|---|
| 5 | * and may only be used, duplicated, modified or distributed pursuant to the terms and |
|---|
| 6 | * conditions of a separate, written license agreement executed between you and Broadcom |
|---|
| 7 | * (an "Authorized License"). Except as set forth in an Authorized License, Broadcom grants |
|---|
| 8 | * no license (express or implied), right to use, or waiver of any kind with respect to the |
|---|
| 9 | * Software, and Broadcom expressly reserves all rights in and to the Software and all |
|---|
| 10 | * intellectual property rights therein. IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU |
|---|
| 11 | * HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY |
|---|
| 12 | * NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE. |
|---|
| 13 | * |
|---|
| 14 | * Except as expressly set forth in the Authorized License, |
|---|
| 15 | * |
|---|
| 16 | * 1. This program, including its structure, sequence and organization, constitutes the valuable trade |
|---|
| 17 | * secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof, |
|---|
| 18 | * and to use this information only in connection with your use of Broadcom integrated circuit products. |
|---|
| 19 | * |
|---|
| 20 | * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" |
|---|
| 21 | * AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR |
|---|
| 22 | * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO |
|---|
| 23 | * THE SOFTWARE. BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES |
|---|
| 24 | * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, |
|---|
| 25 | * LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION |
|---|
| 26 | * OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF |
|---|
| 27 | * USE OR PERFORMANCE OF THE SOFTWARE. |
|---|
| 28 | * |
|---|
| 29 | * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS |
|---|
| 30 | * LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR |
|---|
| 31 | * EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR |
|---|
| 32 | * USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF |
|---|
| 33 | * THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT |
|---|
| 34 | * ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE |
|---|
| 35 | * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF |
|---|
| 36 | * ANY LIMITED REMEDY. |
|---|
| 37 | * |
|---|
| 38 | * $brcm_Workfile: nexus_audio_dac.c $ |
|---|
| 39 | * $brcm_Revision: 7 $ |
|---|
| 40 | * $brcm_Date: 7/6/11 6:41p $ |
|---|
| 41 | * |
|---|
| 42 | * API Description: |
|---|
| 43 | * API name: AudioDac |
|---|
| 44 | * Specific APIs related to audio DAC outputs. |
|---|
| 45 | * |
|---|
| 46 | * Revision History: |
|---|
| 47 | * |
|---|
| 48 | * $brcm_Log: /nexus/modules/audio/7422/src/nexus_audio_dac.c $ |
|---|
| 49 | * |
|---|
| 50 | * 7 7/6/11 6:41p jgarrett |
|---|
| 51 | * SW7552-55: Mapping channelMode to stereoMode |
|---|
| 52 | * |
|---|
| 53 | * 6 5/25/11 5:16p jgarrett |
|---|
| 54 | * SW7425-408: Adding BDBG_OBJECT to input/output types and MS11 features |
|---|
| 55 | * |
|---|
| 56 | * 5 4/26/11 11:35a jgarrett |
|---|
| 57 | * SW7425-437: Resolving kernel mode shutdown issues |
|---|
| 58 | * |
|---|
| 59 | * 4 3/25/11 11:55a jgarrett |
|---|
| 60 | * SW7422-375: Refactoring peak gain api |
|---|
| 61 | * |
|---|
| 62 | * 3 3/23/11 7:12p jgarrett |
|---|
| 63 | * SW7422-375: Adding peakingFilter settings |
|---|
| 64 | * |
|---|
| 65 | * 2 2/22/11 5:44p jgarrett |
|---|
| 66 | * SW7422-146: Implemented type renaming based on filter graph review |
|---|
| 67 | * comments |
|---|
| 68 | * |
|---|
| 69 | * 1 12/17/10 3:56p jgarrett |
|---|
| 70 | * SW7422-146: Adding initial nexus on APE for 7422 |
|---|
| 71 | * |
|---|
| 72 | ***************************************************************************/ |
|---|
| 73 | #include "nexus_audio_module.h" |
|---|
| 74 | |
|---|
| 75 | BDBG_MODULE(nexus_audio_dac); |
|---|
| 76 | |
|---|
| 77 | BDBG_OBJECT_ID(NEXUS_AudioDac); |
|---|
| 78 | typedef struct NEXUS_AudioDac |
|---|
| 79 | { |
|---|
| 80 | BDBG_OBJECT(NEXUS_AudioDac) |
|---|
| 81 | bool opened; |
|---|
| 82 | BAPE_DacHandle handle; |
|---|
| 83 | NEXUS_AudioDacSettings settings; |
|---|
| 84 | NEXUS_AudioOutputObject connector; |
|---|
| 85 | } NEXUS_AudioDac; |
|---|
| 86 | |
|---|
| 87 | static NEXUS_AudioDac g_dacs[NEXUS_NUM_AUDIO_DACS]; |
|---|
| 88 | |
|---|
| 89 | static NEXUS_Error NEXUS_AudioDac_P_SetChannelMode(void *pHandle, NEXUS_AudioChannelMode channelMode); |
|---|
| 90 | |
|---|
| 91 | /*************************************************************************** |
|---|
| 92 | Summary: |
|---|
| 93 | Get default settings for an audio DAC |
|---|
| 94 | See Also: |
|---|
| 95 | |
|---|
| 96 | ***************************************************************************/ |
|---|
| 97 | void NEXUS_AudioDac_GetDefaultSettings( |
|---|
| 98 | NEXUS_AudioDacSettings *pSettings /* [out] default settings */ |
|---|
| 99 | ) |
|---|
| 100 | { |
|---|
| 101 | BAPE_DacSettings dacSettings; |
|---|
| 102 | |
|---|
| 103 | BKNI_Memset(pSettings, 0, sizeof(*pSettings)); |
|---|
| 104 | |
|---|
| 105 | BAPE_Dac_GetDefaultSettings(&dacSettings); |
|---|
| 106 | |
|---|
| 107 | switch ( dacSettings.muteType ) |
|---|
| 108 | { |
|---|
| 109 | default: |
|---|
| 110 | case BAPE_DacMuteType_eDrive0: |
|---|
| 111 | pSettings->muteType = NEXUS_AudioDacMuteType_eDrive0; |
|---|
| 112 | break; |
|---|
| 113 | case BAPE_DacMuteType_eDriveNegative1: |
|---|
| 114 | pSettings->muteType = NEXUS_AudioDacMuteType_eDriveNegative1; |
|---|
| 115 | break; |
|---|
| 116 | case BAPE_DacMuteType_eCustom: |
|---|
| 117 | pSettings->muteType = NEXUS_AudioDacMuteType_eCustomValue; |
|---|
| 118 | break; |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | pSettings->muteValueLeft = dacSettings.customLeftValue; |
|---|
| 122 | pSettings->muteValueRight = dacSettings.customRightValue; |
|---|
| 123 | pSettings->testTone.sharedSamples = true; |
|---|
| 124 | pSettings->testTone.numSamplesLeft = 64; |
|---|
| 125 | pSettings->testTone.numSamplesRight = 64; |
|---|
| 126 | pSettings->testTone.sampleRate = 48000; |
|---|
| 127 | pSettings->peakGain = dacSettings.peakGain; |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | /*************************************************************************** |
|---|
| 131 | Summary: |
|---|
| 132 | Open an audio DAC |
|---|
| 133 | See Also: |
|---|
| 134 | NEXUS_AudioDac_Close |
|---|
| 135 | ***************************************************************************/ |
|---|
| 136 | NEXUS_AudioDacHandle NEXUS_AudioDac_Open( |
|---|
| 137 | unsigned index, |
|---|
| 138 | const NEXUS_AudioDacSettings *pSettings /* Pass NULL for default settings */ |
|---|
| 139 | ) |
|---|
| 140 | { |
|---|
| 141 | BAPE_DacHandle dacHandle; |
|---|
| 142 | BERR_Code errCode; |
|---|
| 143 | BAPE_OutputPort connector; |
|---|
| 144 | |
|---|
| 145 | /* Sanity check */ |
|---|
| 146 | if ( index >= NEXUS_NUM_AUDIO_DACS ) |
|---|
| 147 | { |
|---|
| 148 | BDBG_ERR(("Dac Index %u out of range", index)); |
|---|
| 149 | return NULL; |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | if ( g_dacs[index].opened ) |
|---|
| 153 | { |
|---|
| 154 | BDBG_ERR(("Dac %d already open", index)); |
|---|
| 155 | return NULL; |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | errCode = BAPE_Dac_Open(NEXUS_AUDIO_DEVICE_HANDLE, index, NULL, &dacHandle); |
|---|
| 159 | if ( errCode ) |
|---|
| 160 | { |
|---|
| 161 | (void)BERR_TRACE(errCode); |
|---|
| 162 | return NULL; |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | g_dacs[index].opened = true; |
|---|
| 166 | /* Initialize connector */ |
|---|
| 167 | g_dacs[index].handle = dacHandle; |
|---|
| 168 | NEXUS_AUDIO_OUTPUT_INIT(&g_dacs[index].connector, NEXUS_AudioOutputType_eDac, &g_dacs[index]); |
|---|
| 169 | g_dacs[index].connector.setChannelMode = NEXUS_AudioDac_P_SetChannelMode; |
|---|
| 170 | BDBG_OBJECT_SET(&g_dacs[index], NEXUS_AudioDac); |
|---|
| 171 | NEXUS_AudioDac_SetSettings(&g_dacs[index], pSettings); |
|---|
| 172 | |
|---|
| 173 | BAPE_Dac_GetOutputPort(dacHandle, &connector); |
|---|
| 174 | g_dacs[index].connector.port = (uint32_t)connector; |
|---|
| 175 | |
|---|
| 176 | /* Success */ |
|---|
| 177 | return &g_dacs[index]; |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | /*************************************************************************** |
|---|
| 182 | Summary: |
|---|
| 183 | Close an audio DAC |
|---|
| 184 | Description: |
|---|
| 185 | Input to the DAC must be removed prior to closing. |
|---|
| 186 | See Also: |
|---|
| 187 | NEXUS_AudioDac_Open |
|---|
| 188 | NEXUS_AudioOutput_RemoveInput |
|---|
| 189 | NEXUS_AudioOutput_RemoveAllInputs |
|---|
| 190 | ***************************************************************************/ |
|---|
| 191 | void NEXUS_AudioDac_Close( |
|---|
| 192 | NEXUS_AudioDacHandle handle |
|---|
| 193 | ) |
|---|
| 194 | { |
|---|
| 195 | BDBG_OBJECT_ASSERT(handle, NEXUS_AudioDac); |
|---|
| 196 | |
|---|
| 197 | NEXUS_AudioOutput_Shutdown(&handle->connector); |
|---|
| 198 | BAPE_Dac_Close(handle->handle); |
|---|
| 199 | BKNI_Memset(handle, 0, sizeof(NEXUS_AudioDac)); |
|---|
| 200 | } |
|---|
| 201 | |
|---|
| 202 | /*************************************************************************** |
|---|
| 203 | Summary: |
|---|
| 204 | Get Settings for an audio DAC |
|---|
| 205 | See Also: |
|---|
| 206 | NEXUS_AudioDac_SetSettings |
|---|
| 207 | ***************************************************************************/ |
|---|
| 208 | void NEXUS_AudioDac_GetSettings( |
|---|
| 209 | NEXUS_AudioDacHandle handle, |
|---|
| 210 | NEXUS_AudioDacSettings *pSettings /* [out] Settings */ |
|---|
| 211 | ) |
|---|
| 212 | { |
|---|
| 213 | /* Sanity Check */ |
|---|
| 214 | BDBG_OBJECT_ASSERT(handle, NEXUS_AudioDac); |
|---|
| 215 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 216 | |
|---|
| 217 | /* Copy settings */ |
|---|
| 218 | *pSettings = handle->settings; |
|---|
| 219 | } |
|---|
| 220 | |
|---|
| 221 | /*************************************************************************** |
|---|
| 222 | Summary: |
|---|
| 223 | Set Settings for an audio DAC |
|---|
| 224 | See Also: |
|---|
| 225 | NEXUS_AudioDac_GetSettings |
|---|
| 226 | ***************************************************************************/ |
|---|
| 227 | NEXUS_Error NEXUS_AudioDac_SetSettings( |
|---|
| 228 | NEXUS_AudioDacHandle handle, |
|---|
| 229 | const NEXUS_AudioDacSettings *pSettings /* [in] Settings */ |
|---|
| 230 | ) |
|---|
| 231 | { |
|---|
| 232 | NEXUS_AudioDacSettings settings; |
|---|
| 233 | BAPE_DacSettings dacSettings; |
|---|
| 234 | NEXUS_Error errCode; |
|---|
| 235 | |
|---|
| 236 | /* Sanity Check */ |
|---|
| 237 | BDBG_OBJECT_ASSERT(handle, NEXUS_AudioDac); |
|---|
| 238 | |
|---|
| 239 | if ( NULL == pSettings ) |
|---|
| 240 | { |
|---|
| 241 | NEXUS_AudioDac_GetDefaultSettings(&settings); |
|---|
| 242 | pSettings = &settings; |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | BAPE_Dac_GetSettings(handle->handle, &dacSettings); |
|---|
| 246 | |
|---|
| 247 | /* Adjust RAP parameters to match mute type */ |
|---|
| 248 | switch ( pSettings->muteType ) |
|---|
| 249 | { |
|---|
| 250 | default: |
|---|
| 251 | BDBG_ERR(("Mute mode %d not supported on this chipset", pSettings->muteType)); |
|---|
| 252 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 253 | case NEXUS_AudioDacMuteType_eDrive0: |
|---|
| 254 | dacSettings.muteType = BAPE_DacMuteType_eDrive0; |
|---|
| 255 | break; |
|---|
| 256 | case NEXUS_AudioDacMuteType_eDriveNegative1: |
|---|
| 257 | dacSettings.muteType = BAPE_DacMuteType_eDriveNegative1; |
|---|
| 258 | break; |
|---|
| 259 | case NEXUS_AudioDacMuteType_eCustomValue: |
|---|
| 260 | dacSettings.muteType = BAPE_DacMuteType_eCustom; |
|---|
| 261 | dacSettings.customLeftValue = pSettings->muteValueLeft; |
|---|
| 262 | dacSettings.customRightValue = pSettings->muteValueRight; |
|---|
| 263 | break; |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | dacSettings.testTone.enabled = pSettings->testTone.enabled; |
|---|
| 267 | BDBG_CASSERT(sizeof(dacSettings.testTone.samples) == sizeof(pSettings->testTone.samples)); |
|---|
| 268 | BKNI_Memcpy(dacSettings.testTone.samples, pSettings->testTone.samples, sizeof(pSettings->testTone.samples)); |
|---|
| 269 | dacSettings.testTone.zeroOnLeft = pSettings->testTone.zeroOnLeft; |
|---|
| 270 | dacSettings.testTone.zeroOnRight = pSettings->testTone.zeroOnRight; |
|---|
| 271 | dacSettings.testTone.sharedSamples = pSettings->testTone.sharedSamples; |
|---|
| 272 | dacSettings.testTone.numSamplesLeft = pSettings->testTone.numSamplesLeft; |
|---|
| 273 | dacSettings.testTone.numSamplesRight = pSettings->testTone.numSamplesRight; |
|---|
| 274 | dacSettings.testTone.sampleRate = pSettings->testTone.sampleRate; |
|---|
| 275 | dacSettings.peakGain = pSettings->peakGain; |
|---|
| 276 | |
|---|
| 277 | errCode = BAPE_Dac_SetSettings(handle->handle, &dacSettings); |
|---|
| 278 | if ( errCode ) |
|---|
| 279 | { |
|---|
| 280 | return BERR_TRACE(errCode); |
|---|
| 281 | } |
|---|
| 282 | |
|---|
| 283 | handle->settings = *pSettings; |
|---|
| 284 | |
|---|
| 285 | return BERR_SUCCESS; |
|---|
| 286 | } |
|---|
| 287 | |
|---|
| 288 | /*************************************************************************** |
|---|
| 289 | Summary: |
|---|
| 290 | Get the audio connector for an audio DAC |
|---|
| 291 | See Also: |
|---|
| 292 | |
|---|
| 293 | ***************************************************************************/ |
|---|
| 294 | NEXUS_AudioOutput NEXUS_AudioDac_GetConnector( |
|---|
| 295 | NEXUS_AudioDacHandle handle |
|---|
| 296 | ) |
|---|
| 297 | { |
|---|
| 298 | BDBG_OBJECT_ASSERT(handle, NEXUS_AudioDac); |
|---|
| 299 | return &handle->connector; |
|---|
| 300 | } |
|---|
| 301 | |
|---|
| 302 | static NEXUS_Error NEXUS_AudioDac_P_SetChannelMode(void *pHandle, NEXUS_AudioChannelMode channelMode) |
|---|
| 303 | { |
|---|
| 304 | BERR_Code errCode; |
|---|
| 305 | BAPE_DacSettings dacSettings; |
|---|
| 306 | |
|---|
| 307 | NEXUS_AudioDacHandle handle = (NEXUS_AudioDacHandle) pHandle; |
|---|
| 308 | BDBG_OBJECT_ASSERT(handle, NEXUS_AudioDac); |
|---|
| 309 | |
|---|
| 310 | BAPE_Dac_GetSettings(handle->handle, &dacSettings); |
|---|
| 311 | switch ( channelMode ) |
|---|
| 312 | { |
|---|
| 313 | default: |
|---|
| 314 | case NEXUS_AudioChannelMode_eStereo: |
|---|
| 315 | dacSettings.stereoMode = BAPE_StereoMode_eLeftRight; |
|---|
| 316 | break; |
|---|
| 317 | case NEXUS_AudioChannelMode_eLeft: |
|---|
| 318 | dacSettings.stereoMode = BAPE_StereoMode_eLeftLeft; |
|---|
| 319 | break; |
|---|
| 320 | case NEXUS_AudioChannelMode_eRight: |
|---|
| 321 | dacSettings.stereoMode = BAPE_StereoMode_eRightRight; |
|---|
| 322 | break; |
|---|
| 323 | case NEXUS_AudioChannelMode_eSwapped: |
|---|
| 324 | dacSettings.stereoMode = BAPE_StereoMode_eRightLeft; |
|---|
| 325 | break; |
|---|
| 326 | } |
|---|
| 327 | |
|---|
| 328 | errCode = BAPE_Dac_SetSettings(handle->handle, &dacSettings); |
|---|
| 329 | if ( errCode ) |
|---|
| 330 | { |
|---|
| 331 | return BERR_TRACE(errCode); |
|---|
| 332 | } |
|---|
| 333 | return BERR_SUCCESS; |
|---|
| 334 | } |
|---|
| 335 | |
|---|