| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2006-2011, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: bape_arc.c $ |
|---|
| 11 | * $brcm_Revision: Hydra_Software_Devel/4 $ |
|---|
| 12 | * $brcm_Date: 11/29/11 2:27p $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: Audio Decoder Interface |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: /magnum/portinginterface/ape/7422/bape_arc.c $ |
|---|
| 19 | * |
|---|
| 20 | * Hydra_Software_Devel/4 11/29/11 2:27p gskerl |
|---|
| 21 | * SW7429-18: Added 7429 support for HDMI audio return channel. |
|---|
| 22 | * |
|---|
| 23 | * Hydra_Software_Devel/3 10/2/11 2:44p gskerl |
|---|
| 24 | * SW7231-129: Added support for recovering hardware state after power |
|---|
| 25 | * standby/resume. |
|---|
| 26 | * |
|---|
| 27 | * Hydra_Software_Devel/2 6/8/11 6:43p gskerl |
|---|
| 28 | * SW7425-321: Fixed potential unmuting problem, removed extra arg from |
|---|
| 29 | * BDBG_ERR print |
|---|
| 30 | * |
|---|
| 31 | * Hydra_Software_Devel/1 5/3/11 7:00p gskerl |
|---|
| 32 | * SW7422-354: First attempt at adding support for the audio return |
|---|
| 33 | * channel |
|---|
| 34 | * |
|---|
| 35 | * Hydra_Software_Devel/1 12/16/10 4:05p jgarrett |
|---|
| 36 | * SW7422-146: Initial compilable APE for 7422 |
|---|
| 37 | * |
|---|
| 38 | ***************************************************************************/ |
|---|
| 39 | |
|---|
| 40 | #include "bape.h" |
|---|
| 41 | #include "bape_priv.h" |
|---|
| 42 | |
|---|
| 43 | BDBG_MODULE(bape_audioreturnchannel); |
|---|
| 44 | |
|---|
| 45 | #if BAPE_CHIP_MAX_AUDIO_RETURN_CHANNELS > 0 /* If no audio return channel outputs, then skip all of this and just put in stub funcs at bottom of file. */ |
|---|
| 46 | |
|---|
| 47 | BDBG_OBJECT_ID(BAPE_AudioReturnChannel); |
|---|
| 48 | |
|---|
| 49 | typedef struct BAPE_AudioReturnChannel |
|---|
| 50 | { |
|---|
| 51 | BDBG_OBJECT(BAPE_AudioReturnChannel) |
|---|
| 52 | unsigned index; |
|---|
| 53 | BAPE_Handle deviceHandle; |
|---|
| 54 | BAPE_AudioReturnChannelSettings settings; |
|---|
| 55 | char name[20]; /* Audio Rtn Chan %d */ |
|---|
| 56 | } BAPE_AudioReturnChannel; |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | /* Static function prototypes */ |
|---|
| 60 | static BERR_Code BAPE_AudioReturnChannel_P_ApplySettings( |
|---|
| 61 | BAPE_AudioReturnChannelHandle handle, |
|---|
| 62 | const BAPE_AudioReturnChannelSettings *pSettings, |
|---|
| 63 | bool force |
|---|
| 64 | ); |
|---|
| 65 | |
|---|
| 66 | /* Output port callbacks */ |
|---|
| 67 | /* None. */ |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | /*************************************************************************** |
|---|
| 71 | Public APIs: From bape_output.h |
|---|
| 72 | ***************************************************************************/ |
|---|
| 73 | void BAPE_AudioReturnChannel_GetDefaultSettings( |
|---|
| 74 | BAPE_AudioReturnChannelSettings *pSettings |
|---|
| 75 | ) |
|---|
| 76 | { |
|---|
| 77 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 78 | BKNI_Memset(pSettings, 0, sizeof(*pSettings)); |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | /**************************************************************************/ |
|---|
| 82 | |
|---|
| 83 | BERR_Code BAPE_AudioReturnChannel_Open( |
|---|
| 84 | BAPE_Handle deviceHandle, |
|---|
| 85 | unsigned index, |
|---|
| 86 | const BAPE_AudioReturnChannelSettings *pSettings, |
|---|
| 87 | BAPE_AudioReturnChannelHandle *pHandle /* [out] */ |
|---|
| 88 | ) |
|---|
| 89 | { |
|---|
| 90 | BAPE_AudioReturnChannelSettings defaultSettings; |
|---|
| 91 | BAPE_AudioReturnChannelHandle handle; |
|---|
| 92 | BERR_Code errCode; |
|---|
| 93 | |
|---|
| 94 | BDBG_OBJECT_ASSERT(deviceHandle, BAPE_Device); |
|---|
| 95 | BDBG_ASSERT(NULL != pHandle); |
|---|
| 96 | |
|---|
| 97 | BDBG_MSG(("%s: Opening AudioReturnChannel Output: %u", __FUNCTION__, index)); |
|---|
| 98 | |
|---|
| 99 | *pHandle = NULL; /* Set up to return null handle in case of error. */ |
|---|
| 100 | |
|---|
| 101 | if ( index >= BAPE_CHIP_MAX_AUDIO_RETURN_CHANNELS ) |
|---|
| 102 | { |
|---|
| 103 | BDBG_ERR(("Request to open Audio Return Channel %d but chip only has %u", index, BAPE_CHIP_MAX_AUDIO_RETURN_CHANNELS)); |
|---|
| 104 | return BERR_TRACE(BERR_INVALID_PARAMETER); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | if ( deviceHandle->audioReturnChannels[index] ) |
|---|
| 108 | { |
|---|
| 109 | BDBG_ERR(("Audio Rtn Chan %u already open", index)); |
|---|
| 110 | return BERR_TRACE(BERR_INVALID_PARAMETER); |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | handle = BKNI_Malloc(sizeof(BAPE_AudioReturnChannel)); |
|---|
| 114 | if ( NULL == handle ) |
|---|
| 115 | { |
|---|
| 116 | return BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY); |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | BKNI_Memset(handle, 0, sizeof(BAPE_AudioReturnChannel)); |
|---|
| 120 | BDBG_OBJECT_SET(handle, BAPE_AudioReturnChannel); |
|---|
| 121 | handle->deviceHandle = deviceHandle; |
|---|
| 122 | handle->index = index; |
|---|
| 123 | |
|---|
| 124 | BKNI_Snprintf(handle->name, sizeof(handle->name), "Audio Rtn Chan %u", index); |
|---|
| 125 | |
|---|
| 126 | if ( NULL == pSettings ) |
|---|
| 127 | { |
|---|
| 128 | BAPE_AudioReturnChannel_GetDefaultSettings(&defaultSettings); |
|---|
| 129 | pSettings = &defaultSettings; |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | errCode = BAPE_AudioReturnChannel_SetSettings(handle, pSettings); |
|---|
| 133 | if ( errCode ) |
|---|
| 134 | { |
|---|
| 135 | BAPE_AudioReturnChannel_Close(handle); |
|---|
| 136 | return BERR_TRACE(errCode); |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | *pHandle = handle; |
|---|
| 140 | handle->deviceHandle->audioReturnChannels[index] = handle; |
|---|
| 141 | return BERR_SUCCESS; |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | /**************************************************************************/ |
|---|
| 145 | |
|---|
| 146 | void BAPE_AudioReturnChannel_Close( |
|---|
| 147 | BAPE_AudioReturnChannelHandle handle |
|---|
| 148 | ) |
|---|
| 149 | { |
|---|
| 150 | BAPE_AudioReturnChannelSettings defaults; |
|---|
| 151 | |
|---|
| 152 | BDBG_OBJECT_ASSERT(handle, BAPE_AudioReturnChannel); |
|---|
| 153 | |
|---|
| 154 | /* Set ARC settings back to default values. */ |
|---|
| 155 | BAPE_AudioReturnChannel_GetDefaultSettings(&defaults); |
|---|
| 156 | BAPE_AudioReturnChannel_SetSettings(handle, &defaults); |
|---|
| 157 | |
|---|
| 158 | handle->deviceHandle->audioReturnChannels[handle->index] = NULL; |
|---|
| 159 | BDBG_OBJECT_DESTROY(handle, BAPE_AudioReturnChannel); |
|---|
| 160 | BKNI_Free(handle); |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | /**************************************************************************/ |
|---|
| 164 | |
|---|
| 165 | void BAPE_AudioReturnChannel_GetSettings( |
|---|
| 166 | BAPE_AudioReturnChannelHandle handle, |
|---|
| 167 | BAPE_AudioReturnChannelSettings *pSettings /* [out] */ |
|---|
| 168 | ) |
|---|
| 169 | { |
|---|
| 170 | BDBG_OBJECT_ASSERT(handle, BAPE_AudioReturnChannel); |
|---|
| 171 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 172 | *pSettings = handle->settings; |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | /**************************************************************************/ |
|---|
| 176 | |
|---|
| 177 | BERR_Code BAPE_AudioReturnChannel_SetSettings( |
|---|
| 178 | BAPE_AudioReturnChannelHandle handle, |
|---|
| 179 | const BAPE_AudioReturnChannelSettings *pSettings |
|---|
| 180 | ) |
|---|
| 181 | { |
|---|
| 182 | BERR_Code errCode = BERR_SUCCESS; |
|---|
| 183 | |
|---|
| 184 | BDBG_OBJECT_ASSERT(handle, BAPE_AudioReturnChannel); |
|---|
| 185 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 186 | |
|---|
| 187 | errCode = BAPE_AudioReturnChannel_P_ApplySettings(handle, pSettings, false); /* false => don't force (only update HW for changes) */ |
|---|
| 188 | return errCode; |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | /*************************************************************************** |
|---|
| 192 | BAPE Internal APIs: From bape_fmm_priv.h |
|---|
| 193 | ***************************************************************************/ |
|---|
| 194 | |
|---|
| 195 | BERR_Code BAPE_AudioReturnChannel_P_ResumeFromStandby(BAPE_Handle bapeHandle) |
|---|
| 196 | { |
|---|
| 197 | BERR_Code errCode = BERR_SUCCESS; |
|---|
| 198 | unsigned index; |
|---|
| 199 | |
|---|
| 200 | BDBG_OBJECT_ASSERT(bapeHandle, BAPE_Device); |
|---|
| 201 | |
|---|
| 202 | /* For each opened AudioReturnChannel Output, call the functions necessary to |
|---|
| 203 | * restore the hardware to it's appropriate state. |
|---|
| 204 | */ |
|---|
| 205 | for ( index=0 ; index<BAPE_CHIP_MAX_AUDIO_RETURN_CHANNELS ; index++ ) |
|---|
| 206 | { |
|---|
| 207 | if ( bapeHandle->audioReturnChannels[index] ) /* If this AudioReturnChannel is open... */ |
|---|
| 208 | { |
|---|
| 209 | BAPE_AudioReturnChannelHandle hAudioReturnChannel = bapeHandle->audioReturnChannels[index]; |
|---|
| 210 | |
|---|
| 211 | /* Put the HW into the generic open state. */ |
|---|
| 212 | /* Doesn't apply here. */ |
|---|
| 213 | |
|---|
| 214 | /* Now apply changes for the settings struct. */ |
|---|
| 215 | errCode = BAPE_AudioReturnChannel_P_ApplySettings(hAudioReturnChannel, &hAudioReturnChannel->settings, true); /* true => force update of HW */ |
|---|
| 216 | if ( errCode ) return BERR_TRACE(errCode); |
|---|
| 217 | |
|---|
| 218 | /* Now restore the dynamic stuff from the values saved in the device struct. */ |
|---|
| 219 | /* Nothing to do here for AudioReturnChannel. */ |
|---|
| 220 | } |
|---|
| 221 | } |
|---|
| 222 | return errCode; |
|---|
| 223 | } |
|---|
| 224 | |
|---|
| 225 | /*************************************************************************** |
|---|
| 226 | Private callbacks: Protyped above |
|---|
| 227 | ***************************************************************************/ |
|---|
| 228 | /* No callbacks for AudioReturnChannel. */ |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | /*************************************************************************** |
|---|
| 232 | Private functions: Protyped above |
|---|
| 233 | ***************************************************************************/ |
|---|
| 234 | |
|---|
| 235 | static BERR_Code BAPE_AudioReturnChannel_P_ApplySettings( |
|---|
| 236 | BAPE_AudioReturnChannelHandle handle, |
|---|
| 237 | const BAPE_AudioReturnChannelSettings *pSettings, |
|---|
| 238 | bool force |
|---|
| 239 | ) |
|---|
| 240 | { |
|---|
| 241 | BSTD_UNUSED(force); /* Not needed because hardware is always updated (even if nothing changes). */ |
|---|
| 242 | |
|---|
| 243 | BDBG_OBJECT_ASSERT(handle, BAPE_AudioReturnChannel); |
|---|
| 244 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 245 | |
|---|
| 246 | /* See if they want to change the master. */ |
|---|
| 247 | if (pSettings->master != handle->settings.master) |
|---|
| 248 | { |
|---|
| 249 | /* If they've passed in a new master, make sure it's valid. */ |
|---|
| 250 | if (pSettings->master) |
|---|
| 251 | { |
|---|
| 252 | if ( pSettings->master->type != BAPE_OutputPortType_eSpdifOutput ) { |
|---|
| 253 | BDBG_ERR(("Master: %s is not a SpdifOutput, giving up.\n", pSettings->master->pName )); |
|---|
| 254 | return (BERR_INVALID_PARAMETER); |
|---|
| 255 | } |
|---|
| 256 | BDBG_ASSERT( pSettings->master->index < BAPE_CHIP_MAX_SPDIF_OUTPUTS ); |
|---|
| 257 | } |
|---|
| 258 | |
|---|
| 259 | /* Print the old master if there was one. */ |
|---|
| 260 | if (handle->settings.master) |
|---|
| 261 | { |
|---|
| 262 | BDBG_OBJECT_ASSERT(handle->settings.master, BAPE_OutputPort); |
|---|
| 263 | BDBG_MSG(("Removing master: %s from %s\n", handle->settings.master->pName, handle->name )); |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | /* Print the new master if there is one. */ |
|---|
| 267 | if (pSettings->master) |
|---|
| 268 | { |
|---|
| 269 | BDBG_OBJECT_ASSERT(pSettings->master, BAPE_OutputPort); |
|---|
| 270 | BDBG_MSG(("Assigning master: %s to %s\n", pSettings->master->pName, handle->name )); |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | /* Now update the master in the device handle. */ |
|---|
| 274 | handle->settings.master = pSettings->master; |
|---|
| 275 | |
|---|
| 276 | |
|---|
| 277 | /* Currently, we only support one Audio Return Channel maximum, and if there is an |
|---|
| 278 | * audio return channel, there can only be one Spdif output. For anything beyond |
|---|
| 279 | * this, the registers haven't been defined yet. |
|---|
| 280 | * |
|---|
| 281 | * So anyway, make the check here. |
|---|
| 282 | * */ |
|---|
| 283 | |
|---|
| 284 | /* TODO: Allow any Spdif to master any Audio Rtn Chan */ |
|---|
| 285 | /* TODO: Add support for multiple Audio Rtn Chans */ |
|---|
| 286 | |
|---|
| 287 | #if BAPE_CHIP_MAX_SPDIF_OUTPUTS > 1 |
|---|
| 288 | #error "I don't know how to handle Audio Rtn Chan with multiple Spdif outputs" |
|---|
| 289 | #endif |
|---|
| 290 | #if BAPE_CHIP_MAX_AUDIO_RETURN_CHANNELS > 1 |
|---|
| 291 | #error "I don't know how to handle multiple Audio Rtn Channels" |
|---|
| 292 | #endif |
|---|
| 293 | |
|---|
| 294 | } |
|---|
| 295 | |
|---|
| 296 | /* See if they want to change the mute setting. */ |
|---|
| 297 | if (pSettings->muted != handle->settings.muted) |
|---|
| 298 | { |
|---|
| 299 | /* Now update the master in the device handle. */ |
|---|
| 300 | handle->settings.muted = pSettings->muted; |
|---|
| 301 | } |
|---|
| 302 | |
|---|
| 303 | /* Now do the register updates. If we have a master and if |
|---|
| 304 | * we're unmuted, then enable the master's output to go to |
|---|
| 305 | * the audio return channel. |
|---|
| 306 | */ |
|---|
| 307 | if ( handle->settings.master && ! handle->settings.muted ) |
|---|
| 308 | { |
|---|
| 309 | BAPE_Reg_P_UpdateEnum(handle->deviceHandle, BCHP_AUD_MISC_SEROUT_SEL, AUD_MISC_SEROUT_SEL, HDMI_RX_ARC_ENABLE, ENABLE); |
|---|
| 310 | } |
|---|
| 311 | else |
|---|
| 312 | { |
|---|
| 313 | BAPE_Reg_P_UpdateEnum(handle->deviceHandle, BCHP_AUD_MISC_SEROUT_SEL, AUD_MISC_SEROUT_SEL, HDMI_RX_ARC_ENABLE, DISABLE); |
|---|
| 314 | } |
|---|
| 315 | |
|---|
| 316 | return BERR_SUCCESS; |
|---|
| 317 | } |
|---|
| 318 | |
|---|
| 319 | /*************************************************************************** |
|---|
| 320 | Define stub functions for when there are no Audio Return Channel audio outputs. |
|---|
| 321 | ***************************************************************************/ |
|---|
| 322 | #else /* BAPE_CHIP_MAX_AUDIO_RETURN_CHANNELS <= 0 */ |
|---|
| 323 | /* No Audio Return Channel outputs, just use stubbed out functions. */ |
|---|
| 324 | |
|---|
| 325 | void BAPE_AudioReturnChannel_GetDefaultSettings( |
|---|
| 326 | BAPE_AudioReturnChannelSettings *pSettings |
|---|
| 327 | ) |
|---|
| 328 | { |
|---|
| 329 | BSTD_UNUSED(pSettings); |
|---|
| 330 | } |
|---|
| 331 | |
|---|
| 332 | BERR_Code BAPE_AudioReturnChannel_Open( |
|---|
| 333 | BAPE_Handle deviceHandle, |
|---|
| 334 | unsigned index, |
|---|
| 335 | const BAPE_AudioReturnChannelSettings *pSettings, |
|---|
| 336 | BAPE_AudioReturnChannelHandle *pHandle /* [out] */ |
|---|
| 337 | ) |
|---|
| 338 | { |
|---|
| 339 | BSTD_UNUSED(deviceHandle); |
|---|
| 340 | BSTD_UNUSED(index); |
|---|
| 341 | BSTD_UNUSED(pSettings); |
|---|
| 342 | |
|---|
| 343 | *pHandle = NULL; |
|---|
| 344 | |
|---|
| 345 | return BERR_NOT_SUPPORTED; |
|---|
| 346 | } |
|---|
| 347 | |
|---|
| 348 | void BAPE_AudioReturnChannel_Close( |
|---|
| 349 | BAPE_AudioReturnChannelHandle handle |
|---|
| 350 | ) |
|---|
| 351 | { |
|---|
| 352 | BSTD_UNUSED(handle); |
|---|
| 353 | } |
|---|
| 354 | |
|---|
| 355 | void BAPE_AudioReturnChannel_GetSettings( |
|---|
| 356 | BAPE_AudioReturnChannelHandle handle, |
|---|
| 357 | BAPE_AudioReturnChannelSettings *pSettings /* [out] */ |
|---|
| 358 | ) |
|---|
| 359 | { |
|---|
| 360 | BSTD_UNUSED(handle); |
|---|
| 361 | BSTD_UNUSED(pSettings); |
|---|
| 362 | } |
|---|
| 363 | |
|---|
| 364 | BERR_Code BAPE_AudioReturnChannel_SetSettings( |
|---|
| 365 | BAPE_AudioReturnChannelHandle handle, |
|---|
| 366 | const BAPE_AudioReturnChannelSettings *pSettings |
|---|
| 367 | ) |
|---|
| 368 | { |
|---|
| 369 | BSTD_UNUSED(handle); |
|---|
| 370 | BSTD_UNUSED(pSettings); |
|---|
| 371 | |
|---|
| 372 | return BERR_NOT_SUPPORTED; |
|---|
| 373 | } |
|---|
| 374 | BERR_Code BAPE_AudioReturnChannel_P_ResumeFromStandby(BAPE_Handle bapeHandle) |
|---|
| 375 | { |
|---|
| 376 | BSTD_UNUSED(bapeHandle); |
|---|
| 377 | return BERR_SUCCESS; |
|---|
| 378 | } |
|---|
| 379 | |
|---|
| 380 | #endif /* BAPE_CHIP_MAX_AUDIO_RETURN_CHANNELS */ |
|---|
| 381 | |
|---|
| 382 | |
|---|
| 383 | |
|---|
| 384 | |
|---|
| 385 | |
|---|
| 386 | |
|---|
| 387 | |
|---|