| 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_amplifier.c $ |
|---|
| 39 | * $brcm_Revision: 7 $ |
|---|
| 40 | * $brcm_Date: 6/1/11 6:50p $ |
|---|
| 41 | * |
|---|
| 42 | * API Description: |
|---|
| 43 | * API name: Frontend Amplifier |
|---|
| 44 | * Generic APIs for Low-Noise Amplifiers (LNA). |
|---|
| 45 | * |
|---|
| 46 | * Revision History: |
|---|
| 47 | * |
|---|
| 48 | * $brcm_Log: /nexus/modules/frontend/common/src/nexus_amplifier.c $ |
|---|
| 49 | * |
|---|
| 50 | * 7 6/1/11 6:50p mward |
|---|
| 51 | * SW7125-729: SetSettings only if changed. |
|---|
| 52 | * |
|---|
| 53 | * 6 5/26/11 3:24p mward |
|---|
| 54 | * SW7125-928: Add boost/tilt to NEXUS_AmplifierStatus. |
|---|
| 55 | * |
|---|
| 56 | * SW7125-926/2 5/3/11 5:51p mward |
|---|
| 57 | * SW7425-365: fix build warnings for 2.6.37 kernel |
|---|
| 58 | * |
|---|
| 59 | * SW7125-926/1 4/29/11 12:02p mward |
|---|
| 60 | * SW7125-928: Add boost/tilt to NEXUS_AmplifierStatus. |
|---|
| 61 | * |
|---|
| 62 | * 5 5/26/11 3:20p mward |
|---|
| 63 | * SW7125-729: Fix power saver calls, return only on error. |
|---|
| 64 | * |
|---|
| 65 | * 4 3/14/11 4:10p erickson |
|---|
| 66 | * SW7125-830: merge |
|---|
| 67 | * |
|---|
| 68 | * SW7125-828/3 3/11/11 6:08p mward |
|---|
| 69 | * SW7125-830: Adding agcGain to NEXUS_AmplifierStatus. |
|---|
| 70 | * |
|---|
| 71 | * SW7125-828/2 2/18/11 1:45p mward |
|---|
| 72 | * SW7125-830: Changes and clarifications recommended for API approval. |
|---|
| 73 | * |
|---|
| 74 | * SW7125-828/1 2/14/11 12:05p mward |
|---|
| 75 | * SW7125-828: Adding NEXUS_Amplifier_GetStatus(), corresponding to |
|---|
| 76 | * BLNA_GetStatus(). |
|---|
| 77 | * |
|---|
| 78 | * 3 11/22/10 12:36p mward |
|---|
| 79 | * SW7125-729: Use NEXUS_AmplifierSettings.enabled for power savings. |
|---|
| 80 | * |
|---|
| 81 | * SW7125-729/2 11/14/10 10:52a mward |
|---|
| 82 | * SW7125-729: Use NEXUS_AmplifierSettings.enabled rather than separate |
|---|
| 83 | * functions for power saver. |
|---|
| 84 | * |
|---|
| 85 | * SW7125-729/1 11/10/10 5:42p mward |
|---|
| 86 | * SW7125-729: Add NEXUS_Amplifier_SetPowerSaver(). |
|---|
| 87 | * |
|---|
| 88 | * 2 2/7/08 5:36p jgarrett |
|---|
| 89 | * PR 39407: Converting to common close functions |
|---|
| 90 | * |
|---|
| 91 | * 1 1/18/08 2:19p jgarrett |
|---|
| 92 | * PR 38808: Merging to main branch |
|---|
| 93 | * |
|---|
| 94 | * Nexus_Devel/2 11/20/07 6:52p jgarrett |
|---|
| 95 | * PR 37130: Unifying 3563 frontend and platform |
|---|
| 96 | * |
|---|
| 97 | * Nexus_Devel/1 10/5/07 5:52p jgarrett |
|---|
| 98 | * PR 35551: Adding initial version |
|---|
| 99 | * |
|---|
| 100 | ***************************************************************************/ |
|---|
| 101 | |
|---|
| 102 | #include "nexus_frontend_module.h" |
|---|
| 103 | |
|---|
| 104 | BDBG_MODULE(nexus_amplifier); |
|---|
| 105 | |
|---|
| 106 | /*************************************************************************** |
|---|
| 107 | Summary: |
|---|
| 108 | Get the settings of a frontend amplifier |
|---|
| 109 | See Also: |
|---|
| 110 | NEXUS_Amplifier_SetSettings |
|---|
| 111 | ***************************************************************************/ |
|---|
| 112 | void NEXUS_Amplifier_GetSettings( |
|---|
| 113 | NEXUS_AmplifierHandle handle, |
|---|
| 114 | NEXUS_AmplifierSettings *pSettings /* [out] */ |
|---|
| 115 | ) |
|---|
| 116 | { |
|---|
| 117 | #if NEXUS_AMPLIFIER_SUPPORT |
|---|
| 118 | BDBG_ASSERT(NULL != handle); |
|---|
| 119 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 120 | *pSettings = handle->settings; |
|---|
| 121 | #else |
|---|
| 122 | BSTD_UNUSED(handle); |
|---|
| 123 | BSTD_UNUSED(pSettings); |
|---|
| 124 | #endif |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | /*************************************************************************** |
|---|
| 128 | Summary: |
|---|
| 129 | Set the settings of a frontend amplifier |
|---|
| 130 | See Also: |
|---|
| 131 | NEXUS_Amplifier_GetSettings |
|---|
| 132 | ***************************************************************************/ |
|---|
| 133 | NEXUS_Error NEXUS_Amplifier_SetSettings( |
|---|
| 134 | NEXUS_AmplifierHandle handle, |
|---|
| 135 | const NEXUS_AmplifierSettings *pSettings |
|---|
| 136 | ) |
|---|
| 137 | { |
|---|
| 138 | #if NEXUS_AMPLIFIER_SUPPORT |
|---|
| 139 | BERR_Code errCode=BERR_SUCCESS; |
|---|
| 140 | BDBG_ASSERT(NULL != handle); |
|---|
| 141 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 142 | |
|---|
| 143 | if (pSettings->enabled != handle->settings.enabled) |
|---|
| 144 | { |
|---|
| 145 | if (pSettings->enabled) |
|---|
| 146 | { |
|---|
| 147 | errCode = BLNA_DisablePowerSaver(handle->lnaHandle); |
|---|
| 148 | if ( errCode ) |
|---|
| 149 | { |
|---|
| 150 | return BERR_TRACE(errCode); |
|---|
| 151 | } |
|---|
| 152 | } |
|---|
| 153 | else |
|---|
| 154 | { |
|---|
| 155 | errCode = BLNA_EnablePowerSaver(handle->lnaHandle); |
|---|
| 156 | if ( errCode ) |
|---|
| 157 | { |
|---|
| 158 | return BERR_TRACE(errCode); |
|---|
| 159 | } |
|---|
| 160 | } |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | if (pSettings->gainMode != handle->settings.gainMode) |
|---|
| 164 | { |
|---|
| 165 | switch ( pSettings->gainMode ) |
|---|
| 166 | { |
|---|
| 167 | case NEXUS_AmplifierGainMode_eAutomatic: |
|---|
| 168 | errCode = BLNA_EnableAutomaticGainControl(handle->lnaHandle, |
|---|
| 169 | pSettings->gainSettings.automatic.outputLevel, |
|---|
| 170 | pSettings->gainSettings.automatic.deltaValue); |
|---|
| 171 | if ( errCode ) |
|---|
| 172 | { |
|---|
| 173 | return BERR_TRACE(errCode); |
|---|
| 174 | } |
|---|
| 175 | break; |
|---|
| 176 | case NEXUS_AmplifierGainMode_eManual: |
|---|
| 177 | errCode = BLNA_EnableManualGainControl(handle->lnaHandle, |
|---|
| 178 | pSettings->gainSettings.manual.gain); |
|---|
| 179 | if ( errCode ) |
|---|
| 180 | { |
|---|
| 181 | return BERR_TRACE(errCode); |
|---|
| 182 | } |
|---|
| 183 | break; |
|---|
| 184 | default: |
|---|
| 185 | return BERR_TRACE(BERR_INVALID_PARAMETER); |
|---|
| 186 | } |
|---|
| 187 | } |
|---|
| 188 | handle->settings = *pSettings; |
|---|
| 189 | return BERR_SUCCESS; |
|---|
| 190 | #else |
|---|
| 191 | BSTD_UNUSED(handle); |
|---|
| 192 | BSTD_UNUSED(pSettings); |
|---|
| 193 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 194 | #endif |
|---|
| 195 | } |
|---|
| 196 | |
|---|
| 197 | /*************************************************************************** |
|---|
| 198 | Summary: |
|---|
| 199 | Enable the external output for an amplifier port |
|---|
| 200 | See Also: |
|---|
| 201 | |
|---|
| 202 | ***************************************************************************/ |
|---|
| 203 | NEXUS_Error NEXUS_Amplifier_EnableExternalDriver( |
|---|
| 204 | NEXUS_AmplifierHandle handle, |
|---|
| 205 | unsigned portNum, /* The port number you want to enable/disable */ |
|---|
| 206 | bool enabled /* If true, output will be enabled. If false, it will be disabled */ |
|---|
| 207 | ) |
|---|
| 208 | { |
|---|
| 209 | #if NEXUS_AMPLIFIER_SUPPORT |
|---|
| 210 | BDBG_ASSERT(NULL != handle); |
|---|
| 211 | BDBG_ASSERT(NULL != handle->lnaHandle); |
|---|
| 212 | |
|---|
| 213 | if ( enabled ) |
|---|
| 214 | { |
|---|
| 215 | return BLNA_EnableExternalDriver(handle->lnaHandle, portNum); |
|---|
| 216 | } |
|---|
| 217 | else |
|---|
| 218 | { |
|---|
| 219 | return BLNA_DisableExternalDriver(handle->lnaHandle, portNum); |
|---|
| 220 | } |
|---|
| 221 | #else |
|---|
| 222 | BSTD_UNUSED(handle); |
|---|
| 223 | BSTD_UNUSED(portNum); |
|---|
| 224 | BSTD_UNUSED(enabled); |
|---|
| 225 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 226 | #endif |
|---|
| 227 | } |
|---|
| 228 | |
|---|
| 229 | /*************************************************************************** |
|---|
| 230 | Summary: |
|---|
| 231 | Set the amplifier mode for an InBand port |
|---|
| 232 | See Also: |
|---|
| 233 | NEXUS_Amplifier_SetOutOfBandMode |
|---|
| 234 | ***************************************************************************/ |
|---|
| 235 | NEXUS_Error NEXUS_Amplifier_SetInBandMode( |
|---|
| 236 | NEXUS_AmplifierHandle handle, |
|---|
| 237 | unsigned inBandPortNum, |
|---|
| 238 | NEXUS_AmplifierInBandMode inBandMode |
|---|
| 239 | ) |
|---|
| 240 | { |
|---|
| 241 | #if NEXUS_AMPLIFIER_SUPPORT |
|---|
| 242 | BDBG_ASSERT(NULL != handle); |
|---|
| 243 | BDBG_ASSERT(NULL != handle->lnaHandle); |
|---|
| 244 | BDBG_ASSERT(inBandMode < NEXUS_AmplifierInBandMode_eMax); |
|---|
| 245 | |
|---|
| 246 | return BLNA_SetInBandMode(handle->lnaHandle, inBandPortNum, |
|---|
| 247 | (BLNA_InBandMode)inBandMode); |
|---|
| 248 | #else |
|---|
| 249 | BSTD_UNUSED(handle); |
|---|
| 250 | BSTD_UNUSED(inBandPortNum); |
|---|
| 251 | BSTD_UNUSED(inBandMode); |
|---|
| 252 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 253 | #endif |
|---|
| 254 | } |
|---|
| 255 | |
|---|
| 256 | /*************************************************************************** |
|---|
| 257 | Summary: |
|---|
| 258 | Set the amplifier mode for an OutOfBand port |
|---|
| 259 | See Also: |
|---|
| 260 | NEXUS_Amplifier_SetInBandMode |
|---|
| 261 | ***************************************************************************/ |
|---|
| 262 | NEXUS_Error NEXUS_Amplifier_SetOutOfBandMode( |
|---|
| 263 | NEXUS_AmplifierHandle handle, |
|---|
| 264 | unsigned outOfBandPortNum, |
|---|
| 265 | NEXUS_AmplifierOutOfBandMode outOfBandMode |
|---|
| 266 | ) |
|---|
| 267 | { |
|---|
| 268 | #if NEXUS_AMPLIFIER_SUPPORT |
|---|
| 269 | BDBG_ASSERT(NULL != handle); |
|---|
| 270 | BDBG_ASSERT(NULL != handle->lnaHandle); |
|---|
| 271 | BDBG_ASSERT(outOfBandMode < NEXUS_AmplifierOutOfBandMode_eMax); |
|---|
| 272 | |
|---|
| 273 | return BLNA_SetOutOfBandMode(handle->lnaHandle, outOfBandPortNum, |
|---|
| 274 | (BLNA_OutOfBandMode)outOfBandMode); |
|---|
| 275 | #else |
|---|
| 276 | BSTD_UNUSED(handle); |
|---|
| 277 | BSTD_UNUSED(outOfBandPortNum); |
|---|
| 278 | BSTD_UNUSED(outOfBandMode); |
|---|
| 279 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 280 | #endif |
|---|
| 281 | } |
|---|
| 282 | |
|---|
| 283 | /*************************************************************************** |
|---|
| 284 | Summary: |
|---|
| 285 | Close an amplifier handle |
|---|
| 286 | ***************************************************************************/ |
|---|
| 287 | void NEXUS_Amplifier_Close( |
|---|
| 288 | NEXUS_AmplifierHandle handle |
|---|
| 289 | ) |
|---|
| 290 | { |
|---|
| 291 | #if NEXUS_AMPLIFIER_SUPPORT |
|---|
| 292 | BDBG_ASSERT(NULL != handle); |
|---|
| 293 | BLNA_Close(handle->lnaHandle); |
|---|
| 294 | BKNI_Free(handle); |
|---|
| 295 | #else |
|---|
| 296 | BSTD_UNUSED(handle); |
|---|
| 297 | #endif |
|---|
| 298 | } |
|---|
| 299 | |
|---|
| 300 | /*************************************************************************** |
|---|
| 301 | Summary: |
|---|
| 302 | Get the status of a frontend amplifier |
|---|
| 303 | ***************************************************************************/ |
|---|
| 304 | NEXUS_Error NEXUS_Amplifier_GetStatus( |
|---|
| 305 | NEXUS_AmplifierHandle handle, |
|---|
| 306 | NEXUS_AmplifierStatus *pStatus /* [out] */ |
|---|
| 307 | ) |
|---|
| 308 | { |
|---|
| 309 | #if NEXUS_AMPLIFIER_SUPPORT |
|---|
| 310 | BLNA_Status lnaStatus; |
|---|
| 311 | BERR_Code errCode=BERR_SUCCESS; |
|---|
| 312 | BDBG_ASSERT(NULL != handle); |
|---|
| 313 | BDBG_ASSERT(NULL != pStatus); |
|---|
| 314 | BDBG_ASSERT(NEXUS_AMPLIFIER_NUM_INBAND_PORTS<=BLNA_MX_INBAND_PORTS); |
|---|
| 315 | BDBG_ASSERT(NEXUS_AMPLIFIER_NUM_OUTOFBAND_PORTS<=BLNA_MX_OUTOFBAND_PORTS); |
|---|
| 316 | BDBG_ASSERT(NEXUS_AMPLIFIER_NUM_EXTERNAL_DRIVER <=BLNA_MX_EXTDRV); |
|---|
| 317 | BDBG_CASSERT(NEXUS_AmplifierInBandMode_eMax == (NEXUS_AmplifierInBandMode)BQOB_InBandMode_eLast); |
|---|
| 318 | BDBG_CASSERT(NEXUS_AmplifierOutOfBandMode_eMax == (NEXUS_AmplifierOutOfBandMode)BQOB_OutOfBandMode_eLast); |
|---|
| 319 | |
|---|
| 320 | errCode = BLNA_GetStatus(handle->lnaHandle,&lnaStatus); |
|---|
| 321 | if ( errCode ) |
|---|
| 322 | { |
|---|
| 323 | return BERR_TRACE(errCode); |
|---|
| 324 | } |
|---|
| 325 | else |
|---|
| 326 | { |
|---|
| 327 | unsigned i; |
|---|
| 328 | pStatus->gainMode = lnaStatus.gainMode; |
|---|
| 329 | BDBG_MSG(("gainMode = %u",pStatus->gainMode)); |
|---|
| 330 | for (i=0;i<NEXUS_AMPLIFIER_NUM_INBAND_PORTS;i++) |
|---|
| 331 | { |
|---|
| 332 | pStatus->inBandPortMode[i] = (NEXUS_AmplifierInBandMode)lnaStatus.inBandPorts[i]; |
|---|
| 333 | BDBG_MSG(("inBandPortMode[%u] = %u",i,pStatus->inBandPortMode[i])); |
|---|
| 334 | } |
|---|
| 335 | for (i=0;i<NEXUS_AMPLIFIER_NUM_OUTOFBAND_PORTS;i++) |
|---|
| 336 | { |
|---|
| 337 | pStatus->outOfBandPortMode[i] = (NEXUS_AmplifierOutOfBandMode)lnaStatus.outOfBandPorts[i]; |
|---|
| 338 | BDBG_MSG(("outOfBandPortMode[%u] = %u",i,pStatus->outOfBandPortMode[i])); |
|---|
| 339 | } |
|---|
| 340 | for (i=0;i<NEXUS_AMPLIFIER_NUM_EXTERNAL_DRIVER ;i++) |
|---|
| 341 | { |
|---|
| 342 | pStatus->isExternalDriverEnabled[i] = lnaStatus.isExternalDriverEnabled[i]; |
|---|
| 343 | BDBG_MSG(("isExternalDriverEnabled[%u] = %u",i,pStatus->isExternalDriverEnabled[i])); |
|---|
| 344 | } |
|---|
| 345 | pStatus->agcOutputLevel /* units 0.1 dB */ = 2 * lnaStatus.agcOutputLevel /* units 0.2 dB */; |
|---|
| 346 | BDBG_MSG(("agcOutputLevel = %u",pStatus->agcOutputLevel)); |
|---|
| 347 | pStatus->agcDeltaVal /* units 0.1 dB */ = 2 * lnaStatus.agcDeltaVal /* units 0.2 dB */; |
|---|
| 348 | BDBG_MSG(("agcDeltaVal = %u",pStatus->agcDeltaVal)); |
|---|
| 349 | pStatus->manualGainVal /* units 0.1 dB */ = 2 * lnaStatus.manualGainVal /* units 0.2 dB */; |
|---|
| 350 | BDBG_MSG(("manualGainVal = %u",pStatus->manualGainVal)); |
|---|
| 351 | pStatus->gainBoostEnabled = lnaStatus.gainBoostEnabled; |
|---|
| 352 | BDBG_MSG(("gainBoostEnabled = %u",pStatus->gainBoostEnabled)); |
|---|
| 353 | pStatus->superBoostEnabled = lnaStatus.superBoostEnabled; |
|---|
| 354 | BDBG_MSG(("superBoostEnabled = %u",pStatus->superBoostEnabled)); |
|---|
| 355 | pStatus->tiltEnabled = lnaStatus.tiltEnabled; |
|---|
| 356 | BDBG_MSG(("tiltEnabled = %u",pStatus->tiltEnabled)); |
|---|
| 357 | |
|---|
| 358 | errCode = BLNA_GetLnaAgcRegVal(handle->lnaHandle,0,&pStatus->agcGain); |
|---|
| 359 | if ( errCode ) |
|---|
| 360 | { |
|---|
| 361 | return BERR_TRACE(errCode); |
|---|
| 362 | } |
|---|
| 363 | } |
|---|
| 364 | return NEXUS_SUCCESS; |
|---|
| 365 | #else |
|---|
| 366 | BSTD_UNUSED(handle); |
|---|
| 367 | BSTD_UNUSED(pStatus); |
|---|
| 368 | return NEXUS_NOT_SUPPORTED; |
|---|
| 369 | #endif |
|---|
| 370 | } |
|---|
| 371 | |
|---|
| 372 | |
|---|