source: svn/trunk/newcon3bcm2_21bu/magnum/portinginterface/ape/7552/bape_rfmod.c

Last change on this file was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 16.1 KB
Line 
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_rfmod.c $
11 * $brcm_Revision: Hydra_Software_Devel/7 $
12 * $brcm_Date: 11/28/11 6:23p $
13 *
14 * Module Description: Audio Decoder Interface
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /magnum/portinginterface/ape/7422/bape_rfmod.c $
19 *
20 * Hydra_Software_Devel/7   11/28/11 6:23p gskerl
21 * SW7429-18: Added #includes for non-7429 variants of
22 * bchp_hifidac_ctrl<n>.h.
23 *
24 * Hydra_Software_Devel/6   11/16/11 6:48p gskerl
25 * SW7429-18: Corrected misspelling... BAPE_Reg_P_UpdateFieldEnum() ->
26 * BAPE_Reg_P_UpdateField().
27 *
28 * Hydra_Software_Devel/5   11/14/11 3:36p gskerl
29 * SW7429-18: Merging 7429 changes back to main branch.
30 *
31 * Hydra_Software_Devel/SW7429-18/1   10/21/11 6:29p jgarrett
32 * SW7429-18: Initial compileable version for 7429
33 *
34 * Hydra_Software_Devel/4   10/6/11 2:37p gskerl
35 * SW7231-129: Added support for recovering hardware state after power
36 * standby/resume.
37 *
38 * Hydra_Software_Devel/3   6/9/11 1:51p gskerl
39 * SW7552-37: Added RfMod support for all current APE-supported chips.
40 *
41 * Hydra_Software_Devel/2   2/28/11 12:42p gskerl
42 * SW7422-146: Added stub functions to handle BAPE_CHIP_MAX_RFMODS==0
43 *
44 * Hydra_Software_Devel/1   12/16/10 4:05p jgarrett
45 * SW7422-146: Initial compilable APE for 7422
46 *
47 ***************************************************************************/
48
49#include "bape.h"
50#include "bape_priv.h"
51
52#if defined BCHP_HIFIDAC_CTRL_1_REG_START
53    #include "bchp_hifidac_ctrl_1.h"
54#endif
55#if defined BCHP_HIFIDAC_CTRL_0_REG_START
56    #include "bchp_hifidac_ctrl_0.h"
57#endif
58
59#if defined BCHP_HIFIDAC_CTRL1_REG_START
60    #include "bchp_hifidac_ctrl1.h"
61#endif
62#if defined BCHP_HIFIDAC_CTRL0_REG_START
63    #include "bchp_hifidac_ctrl0.h"
64#endif
65
66BDBG_MODULE(bape_rfmod);
67
68#if BAPE_CHIP_MAX_RFMODS > 0   /* If no RF modulator outputs, then skip all of this and just put in stub funcs at bottom of file. */
69
70BDBG_OBJECT_ID(BAPE_RfMod);
71
72typedef struct BAPE_RfMod
73{
74    BDBG_OBJECT(BAPE_RfMod)
75    BAPE_Handle deviceHandle;
76    BAPE_RfModSettings settings;
77    unsigned index;
78    char name[16];   /* RF Mod %d */
79} BAPE_RfMod;
80
81
82/* Static function prototypes */
83static void BAPE_RfMod_P_SetDacMute(BAPE_RfModHandle handle, unsigned dacIndex, bool muteRfm);
84
85/* Output port callbacks */
86    /* None */
87
88
89/***************************************************************************
90        Public APIs: From bape_output.h
91***************************************************************************/
92
93void BAPE_RfMod_GetDefaultSettings(
94    BAPE_RfModSettings *pSettings
95    )
96{
97    BDBG_ASSERT(NULL != pSettings);
98    BKNI_Memset(pSettings, 0, sizeof(*pSettings));
99}
100
101/**************************************************************************/
102
103BERR_Code BAPE_RfMod_Open(
104    BAPE_Handle deviceHandle,
105    unsigned index,
106    const BAPE_RfModSettings *pSettings,
107    BAPE_RfModHandle *pHandle             /* [out] */
108    )
109{
110    BERR_Code errCode;
111    BAPE_RfModHandle handle;
112    BAPE_RfModSettings defaultSettings;
113
114    BDBG_OBJECT_ASSERT(deviceHandle, BAPE_Device);
115    BDBG_ASSERT(NULL != pHandle);
116
117    BDBG_MSG(("%s: Opening RFMOD Output: %u", __FUNCTION__, index));
118
119    *pHandle = NULL;    /* Set up to return null handle in case of error. */
120
121    if ( index >= BAPE_CHIP_MAX_RFMODS )
122    {
123        BDBG_ERR(("Request to open RFMOD %d but chip only has %u RFMODs", index, BAPE_CHIP_MAX_RFMODS));
124        return BERR_TRACE(BERR_INVALID_PARAMETER);
125    }
126
127    if ( deviceHandle->rfmods[index] )
128    {
129        BDBG_ERR(("RFMOD %u already open", index));
130        return BERR_TRACE(BERR_INVALID_PARAMETER);
131    }
132
133    /* Allocate the device structure, then fill in all the fields. */
134    handle = BKNI_Malloc(sizeof(BAPE_RfMod));
135    if ( NULL == handle )
136    {
137        return BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);
138    }
139
140    BKNI_Memset(handle, 0, sizeof(BAPE_RfMod));
141    BDBG_OBJECT_SET(handle, BAPE_RfMod);
142    handle->deviceHandle = deviceHandle;
143    handle->index = index;
144    BKNI_Snprintf(handle->name, sizeof(handle->name), "RF Mod %u", index);
145
146    /* Init to specified settings */
147    if ( NULL == pSettings )
148    {
149        BAPE_RfMod_GetDefaultSettings(&defaultSettings);
150        pSettings = &defaultSettings;
151    }
152
153    errCode = BAPE_RfMod_SetSettings(handle, pSettings);
154    if ( errCode )
155    {
156        BAPE_RfMod_Close(handle);
157        return BERR_TRACE(errCode);
158    }
159
160    deviceHandle->rfmods[index] = handle;
161    *pHandle = handle;
162    return BERR_SUCCESS;
163}
164
165/**************************************************************************/
166
167void BAPE_RfMod_Close(
168    BAPE_RfModHandle handle
169    )
170{
171    BAPE_RfModSettings defaults;
172
173    BDBG_OBJECT_ASSERT(handle, BAPE_RfMod);
174
175    BAPE_RfMod_GetDefaultSettings(&defaults);
176    BAPE_RfMod_SetSettings(handle, &defaults);
177
178    handle->deviceHandle->rfmods[handle->index] = NULL;
179    BDBG_OBJECT_DESTROY(handle, BAPE_RfMod);
180    BKNI_Free(handle);
181}
182
183/**************************************************************************/
184
185void BAPE_RfMod_GetSettings(
186    BAPE_RfModHandle handle,
187    BAPE_RfModSettings *pSettings     /* [out] */
188    )
189{
190    BDBG_OBJECT_ASSERT(handle, BAPE_RfMod);
191    BDBG_ASSERT(NULL != pSettings);
192    *pSettings = handle->settings;
193}
194
195/**************************************************************************/
196
197BERR_Code BAPE_RfMod_SetSettings(
198    BAPE_RfModHandle handle,
199    const BAPE_RfModSettings *pSettings
200    )
201{
202    BAPE_OutputPort     oldMaster = NULL;
203
204    BDBG_OBJECT_ASSERT(handle, BAPE_RfMod);
205    BDBG_ASSERT(NULL != pSettings);
206
207    /* See if they want to change the  master. */
208    if (pSettings->master != handle->settings.master)
209    {
210        oldMaster = handle->settings.master;    /* Save this so we can mute the old master later */
211
212        /* If they've passed in a new master, make sure it's valid. */
213        if (pSettings->master)
214        {
215            if ( pSettings->master->type != BAPE_OutputPortType_eDac ) {
216                BDBG_ERR(("Master: %s is not a DAC, giving up.\n", pSettings->master->pName ));
217                return (BERR_INVALID_PARAMETER);
218            }
219            BDBG_ASSERT(  pSettings->master->index < BAPE_CHIP_MAX_DACS );
220        }
221
222        /* Print the old master if there was one. */
223        if (handle->settings.master)
224        {
225            BDBG_OBJECT_ASSERT(handle->settings.master, BAPE_OutputPort);
226            BDBG_MSG(("Removing master: %s from %s\n", handle->settings.master->pName, handle->name ));
227        }
228
229        /* Print the new master if there is one. */
230        if (pSettings->master)
231        {
232            BDBG_OBJECT_ASSERT(pSettings->master, BAPE_OutputPort);
233            BDBG_MSG(("Assigning master: %s to %s\n", pSettings->master->pName, handle->name ));
234        }
235
236        /* Now update the master in the device handle. */
237        handle->settings.master = pSettings->master;
238    }
239
240    /* See if they want to change the mute setting. */
241    if (pSettings->muted != handle->settings.muted)
242    {
243        /* Now update the setting in the device handle. */
244        handle->settings.muted = pSettings->muted;
245    }
246
247    BDBG_ASSERT(NULL==handle->settings.master || BAPE_CHIP_MAX_DACS > handle->settings.master->index);
248
249    /* Now do the register updates. */ 
250    /* If the master DAC is changing, and the previous one was non-NULL, then mute it. */
251    if (oldMaster)
252    {
253        BAPE_RfMod_P_SetDacMute(handle, oldMaster->index, true);
254    }
255
256    /* If we have a master, then go ahead and set the muting and source selection as appropriate.
257     * But if there's no master, then there's nothing to do... the source selection is irrelevant,
258     * and the mute bit is on the master DAC (so there's nothing to mute).
259     */ 
260    if (handle->settings.master)
261    {
262        bool muteRfm = true;       /* Assume that we'll be muting the RF Mod */
263
264        /* Determine the mute state... Only unmute if the RFMod has a master (DAC) and has
265         * been requested to unmute.  Otherwise, keep it muted.
266         */ 
267        if (!handle->settings.muted)
268        {
269            muteRfm = false;
270        }
271
272        /* If there's more than one DAC, then we'll have to tell the RfMod which DAC  to take its
273         * input from.  So see if there are any RfMod source selection register fields defined.
274         */
275        #if defined (BCHP_AUD_FMM_MISC_HIFIOUT_SEL_RFMOD_SEL_MASK) || defined (BCHP_AUD_FMM_MISC_HIFIOUT_SEL_RFMOD0_SEL_MASK)
276            {
277                uint32_t srcSelRegAddr,  srcSelRegVal;
278
279                /* If we are muting, do it now, before selecting the source. If unmuting, don't do it
280                 * until after we do the source selection.
281                 */
282                if (muteRfm)
283                {
284                    BAPE_RfMod_P_SetDacMute(handle, handle->settings.master->index, muteRfm);
285                }
286     
287                srcSelRegAddr = BCHP_AUD_FMM_MISC_HIFIOUT_SEL;
288                srcSelRegVal = BREG_Read32(handle->deviceHandle->regHandle, srcSelRegAddr);
289       
290                #if BAPE_CHIP_MAX_DACS > 3
291                    #error "Check this code to see if srcSelVal is being computed correctly"
292                #endif
293       
294                #if defined  BCHP_AUD_FMM_MISC_HIFIOUT_SEL_RFMOD_SEL_MASK  /* one RFMod */
295                BDBG_ASSERT(0 == handle->index);
296   
297                    srcSelRegVal &= ~ BCHP_MASK(AUD_FMM_MISC_HIFIOUT_SEL, RFMOD_SEL);
298                    srcSelRegVal |=   BCHP_FIELD_DATA(AUD_FMM_MISC_HIFIOUT_SEL, RFMOD_SEL, handle->settings.master->index );
299   
300                #elif defined BCHP_AUD_FMM_MISC_HIFIOUT_SEL_RFMOD0_SEL_MASK  /* Multiple RFMods*/
301   
302                    if (0 == handle->index)
303                    {
304                        srcSelRegVal &= ~ BCHP_MASK(AUD_FMM_MISC_HIFIOUT_SEL, RFMOD0_SEL);
305                        srcSelRegVal |=   BCHP_FIELD_DATA(AUD_FMM_MISC_HIFIOUT_SEL, RFMOD0_SEL, handle->settings.master->index );
306                    }
307                    #if BAPE_CHIP_MAX_RFMODS > 1
308                        else if (1 == handle->index)
309                        {
310                            srcSelRegVal &= ~ BCHP_MASK(AUD_FMM_MISC_HIFIOUT_SEL, RFMOD1_SEL);
311                            srcSelRegVal |=   BCHP_FIELD_DATA(AUD_FMM_MISC_HIFIOUT_SEL, RFMOD1_SEL, handle->settings.master->index );
312                        }
313                    #endif  /*  BAPE_CHIP_MAX_RFMODS > 1 */
314                    #if BAPE_CHIP_MAX_RFMODS > 2
315                        else if (2 == handle->index)
316                        {
317                            srcSelRegVal &= ~ BCHP_MASK(AUD_FMM_MISC_HIFIOUT_SEL, RFMOD2_SEL);
318                            srcSelRegVal |=   BCHP_FIELD_DATA(AUD_FMM_MISC_HIFIOUT_SEL, RFMOD2_SEL, handle->settings.master->index );
319                        }
320                    #endif  /*  BAPE_CHIP_MAX_RFMODS > 2 */
321                    #if BAPE_CHIP_MAX_RFMODS > 3
322                        #error "Need to add support for more than 3 RF modulators"
323                    #endif /* BAPE_CHIP_MAX_RFMODS > 3 */
324                    else
325                    {
326                        BDBG_ERR(("RF Mod index:%u is invalid"));
327                        BDBG_ASSERT(false);
328                    }
329                #else
330                    #error "I don't know how to fill in the RFMOD_SEL field!"
331                #endif
332       
333                BREG_Write32(handle->deviceHandle->regHandle, srcSelRegAddr, srcSelRegVal);
334   
335                /* If we're unmuting, then do it now... after the source selection. */
336                if (! muteRfm)
337                {
338                    BAPE_RfMod_P_SetDacMute(handle, handle->settings.master->index, muteRfm);
339                }
340            }
341
342        #else /* There aren't any RF Mod source selection bits, just write the mute/unmute register */
343            BAPE_RfMod_P_SetDacMute(handle, handle->settings.master->index, muteRfm);
344        #endif /* defined (BCHP_AUD_FMM_MISC_HIFIOUT_SEL_RFMOD_SEL_MASK) || defined (BCHP_AUD_FMM_MISC_HIFIOUT_SEL_RFMOD0_SEL_MASK) */
345   
346    }
347
348    handle->settings = *pSettings;
349    return BERR_SUCCESS;
350}
351
352/***************************************************************************
353        BAPE Internal APIs: From bape_fmm_priv.h
354***************************************************************************/
355
356BERR_Code BAPE_RfMod_P_ResumeFromStandby(BAPE_Handle bapeHandle)
357{
358    BERR_Code   errCode = BERR_SUCCESS;
359    unsigned    rfModIndex;
360
361    BDBG_OBJECT_ASSERT(bapeHandle, BAPE_Device);
362
363    /* For each opened RfMod, call the functions necessary to restore the hardware to it's appropriate state. */
364    for ( rfModIndex=0 ; rfModIndex<BAPE_CHIP_MAX_RFMODS ; rfModIndex++ )
365    {
366        if ( bapeHandle->rfmods[rfModIndex] )       /* If this RfMod is open... */
367        {
368            BAPE_RfModHandle hRfMod = bapeHandle->rfmods[rfModIndex];
369
370            /* Put the HW into the generic open state. */
371                /* Nothing to do here for RfMods. */
372           
373            /* Now apply changes for the settings struct. */
374            errCode = BAPE_RfMod_SetSettings(hRfMod, &hRfMod->settings);
375            if ( errCode ) return BERR_TRACE(errCode);
376
377            /* Now restore the dynamic stuff from the values saved in the device struct. */
378                /* Nothing to do here for RfMods. */
379        }
380    }
381    return errCode;
382}
383
384static void BAPE_RfMod_P_SetDacMute(BAPE_RfModHandle handle, unsigned dacIndex, bool muteRfm)
385{
386    uint32_t regAddr;
387
388#if defined BCHP_HIFIDAC_CTRL0_CONFIG
389    regAddr = BCHP_HIFIDAC_CTRL0_CONFIG;
390    #ifdef BCHP_HIFIDAC_CTRL1_CONFIG
391    regAddr += dacIndex * (BCHP_HIFIDAC_CTRL1_CONFIG - BCHP_HIFIDAC_CTRL0_CONFIG);
392    #else
393    BDBG_ASSERT(dacIndex == 0);
394    #endif
395
396    BAPE_Reg_P_UpdateField(handle->deviceHandle, regAddr, HIFIDAC_CTRL0_CONFIG, RFMOD_MUTE, muteRfm?1:0);
397#elif defined BCHP_HIFIDAC_CTRL_0_CONFIG
398    regAddr = BCHP_HIFIDAC_CTRL_0_CONFIG;
399    #ifdef BCHP_HIFIDAC_CTRL_1_CONFIG
400    regAddr += dacIndex * (BCHP_HIFIDAC_CTRL_1_CONFIG - BCHP_HIFIDAC_CTRL_0_CONFIG);
401    #else
402    BDBG_ASSERT(dacIndex == 0);
403    #endif
404
405    BAPE_Reg_P_UpdateField(handle->deviceHandle, regAddr, HIFIDAC_CTRL_0_CONFIG, RFMOD_MUTE, muteRfm?1:0);
406#else
407    #warning Unknown DAC register layout
408#endif
409}
410
411/***************************************************************************
412    Define stub functions for when there are no RF modulator audio outputs.
413***************************************************************************/
414#else /* BAPE_CHIP_MAX_RFMODS <= 0 */
415    /* No RF modulator audio outputs, just use stubbed out functions. */
416
417/**************************************************************************/
418void BAPE_RfMod_GetDefaultSettings(
419    BAPE_RfModSettings *pSettings
420    )
421{
422    BSTD_UNUSED(pSettings);
423}
424
425/**************************************************************************/
426
427BERR_Code BAPE_RfMod_Open(
428    BAPE_Handle deviceHandle,
429    unsigned index,
430    const BAPE_RfModSettings *pSettings,
431    BAPE_RfModHandle *pHandle             /* [out] */
432    )
433{
434    BSTD_UNUSED(deviceHandle);
435    BSTD_UNUSED(index);
436    BSTD_UNUSED(pSettings);
437
438    *pHandle = NULL;
439
440    return BERR_NOT_SUPPORTED;
441}
442
443/**************************************************************************/
444
445void BAPE_RfMod_Close(
446    BAPE_RfModHandle handle
447    )
448{
449    BSTD_UNUSED(handle);
450}
451
452/**************************************************************************/
453
454void BAPE_RfMod_GetSettings(
455    BAPE_RfModHandle handle,
456    BAPE_RfModSettings *pSettings     /* [out] */
457    )
458{
459    BSTD_UNUSED(handle);
460    BSTD_UNUSED(pSettings);
461}
462
463/**************************************************************************/
464
465BERR_Code BAPE_RfMod_SetSettings(
466    BAPE_RfModHandle handle,
467    const BAPE_RfModSettings *pSettings
468    )
469{
470    BSTD_UNUSED(handle);
471    BSTD_UNUSED(pSettings);
472
473    return BERR_NOT_SUPPORTED;
474}
475
476/**************************************************************************/
477
478BERR_Code BAPE_RfMod_P_ResumeFromStandby(BAPE_Handle bapeHandle)
479{
480    BSTD_UNUSED(bapeHandle);
481    return BERR_SUCCESS;
482}
483
484
485#endif /* BAPE_CHIP_MAX_RFMODS */
486
487
488
489
490
491
492
Note: See TracBrowser for help on using the repository browser.