| 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_tuner.c $ |
|---|
| 39 | * $brcm_Revision: 6 $ |
|---|
| 40 | * $brcm_Date: 7/20/11 11:00p $ |
|---|
| 41 | * |
|---|
| 42 | * API Description: |
|---|
| 43 | * API name: Frontend Tuner |
|---|
| 44 | * Generic APIs for tuner device control |
|---|
| 45 | * |
|---|
| 46 | * Revision History: |
|---|
| 47 | * |
|---|
| 48 | * $brcm_Log: /nexus/modules/frontend/common/src/nexus_tuner.c $ |
|---|
| 49 | * |
|---|
| 50 | * 6 7/20/11 11:00p shyi |
|---|
| 51 | * SWDTV-7988: Fixed the size of memory to be cleared |
|---|
| 52 | * |
|---|
| 53 | * 5 3/4/11 3:43p shyi |
|---|
| 54 | * SWDTV-5407: Added the linkage between reading RF input power from a |
|---|
| 55 | * supported tuner and passing the read value to IFD |
|---|
| 56 | * |
|---|
| 57 | * 4 8/26/10 12:00p jgarrett |
|---|
| 58 | * SW35230-900: Merging new tuner interfaces to main branch |
|---|
| 59 | * |
|---|
| 60 | * SW35230-900/3 8/24/10 12:36p shyi |
|---|
| 61 | * SW35230-900: Added handling when NEXUS tuner handle is null, cleaned up |
|---|
| 62 | * 35230 specific settings and rectified a typo in common tuner driver |
|---|
| 63 | * |
|---|
| 64 | * SW35230-900/2 8/20/10 2:09p shyi |
|---|
| 65 | * SW35230-900: Allowing only NEXUS I2C handle when creating new NEXUS |
|---|
| 66 | * tuners, removing obsolete NEXUS tuner SetFrequency API and advertizing |
|---|
| 67 | * new API tune |
|---|
| 68 | * |
|---|
| 69 | * SW35230-900/1 8/12/10 8:24p shyi |
|---|
| 70 | * SW35230-900: Taking TFE tuner changes for I2C read and firmware |
|---|
| 71 | * download capabilities |
|---|
| 72 | * |
|---|
| 73 | * 3 1/23/09 7:25p jgarrett |
|---|
| 74 | * PR 51457: Frontend extension hooks for tuners and frontends/demods |
|---|
| 75 | * |
|---|
| 76 | * 2 2/7/08 5:36p jgarrett |
|---|
| 77 | * PR 39407: Converting to common close functions |
|---|
| 78 | * |
|---|
| 79 | * 1 1/18/08 2:19p jgarrett |
|---|
| 80 | * PR 38808: Merging to main branch |
|---|
| 81 | * |
|---|
| 82 | * Nexus_Devel/2 10/10/07 11:29a jgarrett |
|---|
| 83 | * PR 35551: Adding debug |
|---|
| 84 | * |
|---|
| 85 | * Nexus_Devel/1 10/5/07 5:52p jgarrett |
|---|
| 86 | * PR 35551: Adding initial version |
|---|
| 87 | * |
|---|
| 88 | ***************************************************************************/ |
|---|
| 89 | |
|---|
| 90 | #include "nexus_frontend_module.h" |
|---|
| 91 | |
|---|
| 92 | BDBG_MODULE(nexus_tuner); |
|---|
| 93 | |
|---|
| 94 | BDBG_OBJECT_ID(NEXUS_Tuner); |
|---|
| 95 | |
|---|
| 96 | /*************************************************************************** |
|---|
| 97 | Summary: |
|---|
| 98 | Set the frequency of a tuner device |
|---|
| 99 | ***************************************************************************/ |
|---|
| 100 | NEXUS_Error NEXUS_Tuner_SetFrequency( |
|---|
| 101 | NEXUS_TunerHandle handle, |
|---|
| 102 | NEXUS_TunerMode mode, /* Tuner Mode */ |
|---|
| 103 | unsigned frequency /* In Hz */ |
|---|
| 104 | ) |
|---|
| 105 | { |
|---|
| 106 | BDBG_OBJECT_ASSERT(handle, NEXUS_Tuner); |
|---|
| 107 | if ( handle->setFrequency ) |
|---|
| 108 | { |
|---|
| 109 | BDBG_MSG(("Setting tuner frequency to %d, mode %d", frequency, mode)); |
|---|
| 110 | return handle->setFrequency(handle->pDeviceHandle, mode, frequency); |
|---|
| 111 | } |
|---|
| 112 | else |
|---|
| 113 | { |
|---|
| 114 | if ( NULL != handle->tune ) |
|---|
| 115 | { |
|---|
| 116 | BDBG_ERR(("Please use NEXUS_Tuner_Tune() instead of " |
|---|
| 117 | "NEXUS_Tuner_SetFrequency() for this tuner device.")); |
|---|
| 118 | } |
|---|
| 119 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 120 | } |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | /*************************************************************************** |
|---|
| 124 | Summary: |
|---|
| 125 | Close a tuner handle |
|---|
| 126 | ***************************************************************************/ |
|---|
| 127 | void NEXUS_Tuner_Close( |
|---|
| 128 | NEXUS_TunerHandle handle |
|---|
| 129 | ) |
|---|
| 130 | { |
|---|
| 131 | BDBG_OBJECT_ASSERT(handle, NEXUS_Tuner); |
|---|
| 132 | BDBG_ASSERT(handle->close != NULL); |
|---|
| 133 | handle->close(handle->pDeviceHandle); |
|---|
| 134 | BDBG_OBJECT_DESTROY(handle, NEXUS_Tuner); |
|---|
| 135 | BKNI_Free(handle); |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | /*************************************************************************** |
|---|
| 139 | * Generic method to create a nexus tuner. It will be automatically |
|---|
| 140 | * destroyed when NEXUS_Tuner_Close is called. |
|---|
| 141 | ***************************************************************************/ |
|---|
| 142 | NEXUS_TunerHandle NEXUS_Tuner_P_Create( |
|---|
| 143 | void *pDeviceHandle |
|---|
| 144 | ) |
|---|
| 145 | { |
|---|
| 146 | NEXUS_Tuner *pTuner; |
|---|
| 147 | |
|---|
| 148 | pTuner = BKNI_Malloc(sizeof(NEXUS_Tuner)); |
|---|
| 149 | if ( NULL == pTuner ) |
|---|
| 150 | { |
|---|
| 151 | (void)BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY); |
|---|
| 152 | return NULL; |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | BKNI_Memset(pTuner, 0, sizeof(*pTuner)); |
|---|
| 156 | BDBG_OBJECT_SET(pTuner, NEXUS_Tuner); |
|---|
| 157 | pTuner->pDeviceHandle = pDeviceHandle; |
|---|
| 158 | |
|---|
| 159 | return pTuner; |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | /*************************************************************************** |
|---|
| 163 | Summary: |
|---|
| 164 | Get default settings for a frontend extension |
|---|
| 165 | ****************************************************************************/ |
|---|
| 166 | void NEXUS_Tuner_P_GetDefaultExtensionSettings( |
|---|
| 167 | NEXUS_TunerExtensionSettings *pSettings /* [out] */ |
|---|
| 168 | ) |
|---|
| 169 | { |
|---|
| 170 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 171 | BKNI_Memset(pSettings, 0, sizeof(NEXUS_TunerExtensionSettings)); |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | /*************************************************************************** |
|---|
| 175 | Summary: |
|---|
| 176 | Create a nexus tuner handle from an extension |
|---|
| 177 | |
|---|
| 178 | Description: |
|---|
| 179 | This interface allows a custom platform to easily integrate tuner |
|---|
| 180 | functions for a tuner into the nexus framework. Using this, the standard |
|---|
| 181 | nexus frontend routines can control both your tuner and demodulator if |
|---|
| 182 | desired. |
|---|
| 183 | ****************************************************************************/ |
|---|
| 184 | NEXUS_TunerHandle NEXUS_Tuner_P_CreateExtension( |
|---|
| 185 | const NEXUS_TunerExtensionSettings *pSettings |
|---|
| 186 | ) |
|---|
| 187 | { |
|---|
| 188 | NEXUS_Tuner *pTuner; |
|---|
| 189 | |
|---|
| 190 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 191 | BDBG_ASSERT(NULL != pSettings->close); |
|---|
| 192 | BDBG_ASSERT(NULL != pSettings->setFrequency); |
|---|
| 193 | |
|---|
| 194 | pTuner = NEXUS_Tuner_P_Create(pSettings->pDeviceHandle); |
|---|
| 195 | if ( pTuner ) |
|---|
| 196 | { |
|---|
| 197 | pTuner->ifFrequency = pSettings->ifFrequency; |
|---|
| 198 | pTuner->close = pSettings->close; |
|---|
| 199 | pTuner->setFrequency = pSettings->setFrequency; |
|---|
| 200 | } |
|---|
| 201 | |
|---|
| 202 | return pTuner; |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | void NEXUS_Tuner_Init( |
|---|
| 206 | NEXUS_TunerHandle tuner |
|---|
| 207 | ) |
|---|
| 208 | { |
|---|
| 209 | BDBG_OBJECT_ASSERT(tuner, NEXUS_Tuner); |
|---|
| 210 | if ( NULL != tuner->init ) |
|---|
| 211 | { |
|---|
| 212 | tuner->init(tuner->pDeviceHandle); |
|---|
| 213 | } |
|---|
| 214 | else |
|---|
| 215 | { |
|---|
| 216 | (void)BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 217 | } |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | void NEXUS_Tuner_GetStatus( |
|---|
| 221 | NEXUS_TunerHandle tuner, |
|---|
| 222 | NEXUS_TunerStatus *pStatus /* [out] */ |
|---|
| 223 | ) |
|---|
| 224 | { |
|---|
| 225 | BDBG_OBJECT_ASSERT(tuner, NEXUS_Tuner); |
|---|
| 226 | BDBG_ASSERT(NULL != pStatus); |
|---|
| 227 | if ( tuner->getStatus ) |
|---|
| 228 | { |
|---|
| 229 | tuner->getStatus(tuner->pDeviceHandle, pStatus); |
|---|
| 230 | } |
|---|
| 231 | else |
|---|
| 232 | { |
|---|
| 233 | BKNI_Memset(pStatus, 0, sizeof(*pStatus)); |
|---|
| 234 | (void)BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 235 | } |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | void NEXUS_Tuner_GetDefaultTuneSettings( |
|---|
| 239 | NEXUS_TunerMode mode, |
|---|
| 240 | NEXUS_TunerTuneSettings *pSettings /* [out] */ |
|---|
| 241 | ) |
|---|
| 242 | { |
|---|
| 243 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 244 | BKNI_Memset(pSettings, 0, sizeof(*pSettings)); |
|---|
| 245 | pSettings->mode = mode; |
|---|
| 246 | /* TODO: If specifics are required per-mode, set them here */ |
|---|
| 247 | /* TODO: If each tuner really needs its own GetDefaultTuneSettings, we need a handle passed into this function also. */ |
|---|
| 248 | } |
|---|
| 249 | |
|---|
| 250 | void *NEXUS_Tuner_P_GetAgcScript(NEXUS_TunerHandle tuner) |
|---|
| 251 | { |
|---|
| 252 | BDBG_OBJECT_ASSERT(tuner, NEXUS_Tuner); |
|---|
| 253 | if ( tuner->getAgcScript ) |
|---|
| 254 | { |
|---|
| 255 | return tuner->getAgcScript(tuner->pDeviceHandle); |
|---|
| 256 | } |
|---|
| 257 | else |
|---|
| 258 | { |
|---|
| 259 | return NULL; |
|---|
| 260 | } |
|---|
| 261 | } |
|---|
| 262 | |
|---|
| 263 | NEXUS_Error NEXUS_Tuner_Tune( |
|---|
| 264 | NEXUS_TunerHandle tuner, |
|---|
| 265 | const NEXUS_TunerTuneSettings *pSettings |
|---|
| 266 | ) |
|---|
| 267 | { |
|---|
| 268 | BDBG_OBJECT_ASSERT(tuner, NEXUS_Tuner); |
|---|
| 269 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 270 | if ( tuner->tune ) |
|---|
| 271 | { |
|---|
| 272 | return tuner->tune(tuner->pDeviceHandle, pSettings); |
|---|
| 273 | } |
|---|
| 274 | else if ( tuner->setFrequency ) |
|---|
| 275 | { |
|---|
| 276 | return tuner->setFrequency(tuner->pDeviceHandle, pSettings->mode, pSettings->frequency); |
|---|
| 277 | } |
|---|
| 278 | else |
|---|
| 279 | { |
|---|
| 280 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 281 | } |
|---|
| 282 | } |
|---|
| 283 | |
|---|
| 284 | void NEXUS_Tuner_GetSettings( |
|---|
| 285 | NEXUS_TunerHandle tuner, |
|---|
| 286 | NEXUS_TunerSettings *pSettings /* [out] */ |
|---|
| 287 | ) |
|---|
| 288 | { |
|---|
| 289 | BDBG_OBJECT_ASSERT(tuner, NEXUS_Tuner); |
|---|
| 290 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 291 | if ( tuner->getSettings ) |
|---|
| 292 | { |
|---|
| 293 | tuner->getSettings(tuner->pDeviceHandle, pSettings); |
|---|
| 294 | } |
|---|
| 295 | else |
|---|
| 296 | { |
|---|
| 297 | (void)BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 298 | } |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | NEXUS_Error NEXUS_Tuner_SetSettings( |
|---|
| 302 | NEXUS_TunerHandle tuner, |
|---|
| 303 | const NEXUS_TunerSettings *pSettings |
|---|
| 304 | ) |
|---|
| 305 | { |
|---|
| 306 | BDBG_OBJECT_ASSERT(tuner, NEXUS_Tuner); |
|---|
| 307 | BDBG_ASSERT(NULL != pSettings); |
|---|
| 308 | if ( tuner->setSettings ) |
|---|
| 309 | { |
|---|
| 310 | return tuner->setSettings(tuner->pDeviceHandle, pSettings); |
|---|
| 311 | } |
|---|
| 312 | else |
|---|
| 313 | { |
|---|
| 314 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 315 | } |
|---|
| 316 | } |
|---|
| 317 | |
|---|
| 318 | void NEXUS_Tuner_GetAttributes( |
|---|
| 319 | NEXUS_TunerHandle tuner, |
|---|
| 320 | NEXUS_TunerAttributes *pAttributes /* [out] */ |
|---|
| 321 | ) |
|---|
| 322 | { |
|---|
| 323 | BDBG_OBJECT_ASSERT(tuner, NEXUS_Tuner); |
|---|
| 324 | BDBG_ASSERT(NULL != pAttributes); |
|---|
| 325 | if ( tuner->getAttributes ) |
|---|
| 326 | { |
|---|
| 327 | tuner->getAttributes(tuner->pDeviceHandle, pAttributes); |
|---|
| 328 | } |
|---|
| 329 | else |
|---|
| 330 | { |
|---|
| 331 | BKNI_Memset(pAttributes, 0, sizeof(*pAttributes)); |
|---|
| 332 | (void)BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 333 | } |
|---|
| 334 | } |
|---|
| 335 | |
|---|
| 336 | NEXUS_Error NEXUS_Tuner_ReadPowerLevel( |
|---|
| 337 | NEXUS_TunerHandle tuner, |
|---|
| 338 | int *pPowerLevel |
|---|
| 339 | ) |
|---|
| 340 | { |
|---|
| 341 | BDBG_OBJECT_ASSERT(tuner, NEXUS_Tuner); |
|---|
| 342 | BDBG_ASSERT(NULL != pPowerLevel); |
|---|
| 343 | if ( tuner->readPowerLevel ) |
|---|
| 344 | { |
|---|
| 345 | return tuner->readPowerLevel(tuner->pDeviceHandle, pPowerLevel); |
|---|
| 346 | } |
|---|
| 347 | else |
|---|
| 348 | { |
|---|
| 349 | return BERR_TRACE(BERR_NOT_SUPPORTED); |
|---|
| 350 | } |
|---|
| 351 | } |
|---|
| 352 | |
|---|
| 353 | #if NEXUS_TUNER_SUPPORT |
|---|
| 354 | static NEXUS_Error NEXUS_Tuner_P_SetFrequencyTNR( |
|---|
| 355 | void *handle, |
|---|
| 356 | NEXUS_TunerMode mode, |
|---|
| 357 | unsigned frequency |
|---|
| 358 | ) |
|---|
| 359 | { |
|---|
| 360 | BTNR_Handle tnrHandle = handle; |
|---|
| 361 | return BTNR_SetTunerRfFreq(tnrHandle, |
|---|
| 362 | (uint32_t)frequency, |
|---|
| 363 | (BTNR_TunerMode) mode); |
|---|
| 364 | } |
|---|
| 365 | |
|---|
| 366 | static void NEXUS_Tuner_P_CloseTNR( |
|---|
| 367 | void *handle |
|---|
| 368 | ) |
|---|
| 369 | { |
|---|
| 370 | BTNR_Handle tnrHandle = handle; |
|---|
| 371 | BTNR_Close(tnrHandle); |
|---|
| 372 | } |
|---|
| 373 | |
|---|
| 374 | /*************************************************************************** |
|---|
| 375 | * Method to create a tuner from a BTNR handle |
|---|
| 376 | ***************************************************************************/ |
|---|
| 377 | NEXUS_Tuner *NEXUS_Tuner_P_CreateFromBTNR( |
|---|
| 378 | BTNR_Handle tnrHandle |
|---|
| 379 | ) |
|---|
| 380 | { |
|---|
| 381 | NEXUS_Tuner *pTuner; |
|---|
| 382 | |
|---|
| 383 | pTuner = NEXUS_Tuner_P_Create(tnrHandle); |
|---|
| 384 | if ( pTuner ) |
|---|
| 385 | { |
|---|
| 386 | pTuner->pDeviceHandle = tnrHandle; |
|---|
| 387 | pTuner->close = NEXUS_Tuner_P_CloseTNR; |
|---|
| 388 | pTuner->setFrequency = NEXUS_Tuner_P_SetFrequencyTNR; |
|---|
| 389 | } |
|---|
| 390 | return pTuner; |
|---|
| 391 | } |
|---|
| 392 | #endif |
|---|
| 393 | |
|---|