source: svn/trunk/newcon3bcm2_21bu/nexus/modules/rfm/7552/src/nexus_rfm.c

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

1.phkim

  1. revision copy newcon3sk r27
  • Property svn:executable set to *
File size: 13.0 KB
Line 
1/***************************************************************************
2 *     (c)2007-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_rfm.c $
39 * $brcm_Revision: 14 $
40 * $brcm_Date: 11/22/11 5:48p $
41 *
42 * Module Description:
43 *
44 * Revision History:
45 *
46 * $brcm_Log: /nexus/modules/rfm/7420/src/nexus_rfm.c $
47 *
48 * 14   11/22/11 5:48p jtna
49 * SW7425-1708: add s3 power management for rfm
50 *
51 * 13   9/17/10 5:52p jtna
52 * SW7420-972: move RFM PM from nexus to magnum
53 *
54 * 12   8/26/10 2:59p jtna
55 * SW7420-972: added RFM power management
56 *
57 * 11   11/3/09 2:33p jgarrett
58 * SW7325-646: Fixing scaling of initial volume
59 *
60 * 10   10/30/09 2:31p jgarrett
61 * SW7325-646: Adding volume setting
62 *
63 * 9   9/9/09 1:16p erickson
64 * SW7405-2977: convert to NEXUS_AudioOutputPort
65 *
66 * 8   8/11/09 6:52p jtna
67 * PR56435: fix rfm mute condition
68 *
69 * 7   7/1/09 4:37p jtna
70 * PR56435: RFM dynamic power management support
71 *
72 * 6   1/26/09 1:55p erickson
73 * PR51468: global variable naming convention
74 *
75 * 5   4/18/08 4:20p jgarrett
76 * PR 41623: Setting output port to avoid confusion with SPDIF
77 *
78 * 4   4/11/08 9:53a erickson
79 * PR41246: convert BDBG_OBJECT_UNSET to BDBG_OBJECT_DESTROY if freeing
80 *  memory
81 *
82 * 3   3/31/08 12:33p erickson
83 * PR41073: check result of malloc and fail graciously
84 *
85 * 2   3/4/08 4:31p jgarrett
86 * PR 39405: Saving connection settings
87 *
88 * 1   2/20/08 1:42p erickson
89 * PR39405: added RFM
90 *
91 **************************************************************************/
92#include "nexus_rfm_module.h"
93#include "priv/nexus_rfm_priv.h"
94#include "priv/nexus_core.h"
95#include "priv/nexus_core_video.h"
96#include "priv/nexus_core_audio.h"
97
98BDBG_MODULE(nexus_rfm);
99
100NEXUS_ModuleHandle g_NEXUS_rfmModule;
101static NEXUS_RfmHandle g_NEXUS_rfmHandle[NEXUS_NUM_RFM_OUTPUTS];
102
103void NEXUS_RfmModule_GetDefaultSettings( NEXUS_RfmModuleSettings *pSettings )
104{
105    BKNI_Memset(pSettings, 0, sizeof(*pSettings));
106}
107
108NEXUS_ModuleHandle NEXUS_RfmModule_Init( const NEXUS_RfmModuleSettings *pSettings )
109{
110    NEXUS_ModuleSettings moduleSettings;
111    NEXUS_Error errCode;
112    unsigned i;
113
114    BDBG_ASSERT(NULL == g_NEXUS_rfmModule);
115    BSTD_UNUSED(pSettings);
116
117    /* init global module handle */
118    NEXUS_Module_GetDefaultSettings(&moduleSettings);
119    moduleSettings.priority = NEXUS_ModulePriority_eLow;
120    g_NEXUS_rfmModule = NEXUS_Module_Create("rfm", &moduleSettings);
121    if ( NULL == g_NEXUS_rfmModule )
122    {
123        errCode = BERR_TRACE(BERR_OS_ERROR);
124        return NULL;
125    }
126
127    for (i=0; i<NEXUS_NUM_RFM_OUTPUTS; i++) {
128        g_NEXUS_rfmHandle[i] = NULL;
129    }
130
131    /* Success */
132    return g_NEXUS_rfmModule;
133}
134
135void NEXUS_RfmModule_Uninit(void)
136{
137    BDBG_ASSERT(NULL != g_NEXUS_rfmModule);
138    NEXUS_Module_Destroy(g_NEXUS_rfmModule);
139    g_NEXUS_rfmModule = NULL;
140}
141
142/*********************************************/
143
144BDBG_OBJECT_ID(NEXUS_Rfm);
145
146struct NEXUS_Rfm {
147    BDBG_OBJECT(NEXUS_Rfm)
148    NEXUS_RfmSettings settings;
149    NEXUS_RfmConnectionSettings connectionSettings;
150    NEXUS_VideoOutputObject videoOutput;
151    NEXUS_AudioOutputObject audioOutput;
152    unsigned index;
153    bool volumeChanged;
154
155    BRFM_Handle mRfm;
156};
157
158void NEXUS_Rfm_GetDefaultSettings( NEXUS_RfmSettings *pSettings )
159{
160    BRFM_Settings rfmSettings;
161
162    BKNI_Memset(pSettings, 0, sizeof(*pSettings));
163    BRFM_GetDefaultSettings(&rfmSettings, g_pCoreHandles->chp);
164    pSettings->volume = rfmSettings.volume*100;
165    pSettings->channel = 3;
166}
167
168NEXUS_RfmHandle NEXUS_Rfm_Open( unsigned index, const NEXUS_RfmSettings *pSettings )
169{
170    NEXUS_RfmHandle rfm;
171    NEXUS_RfmSettings defaultSettings;
172    BRFM_Settings rfmSettings;
173    BERR_Code rc;
174
175    if (index >= NEXUS_NUM_RFM_OUTPUTS) {
176        BDBG_ERR(("Invalid RFM index %d", index));
177        return NULL;
178    }
179
180    if (!pSettings) {
181        NEXUS_Rfm_GetDefaultSettings(&defaultSettings);
182        pSettings = &defaultSettings;
183    }
184
185    rfm = BKNI_Malloc(sizeof(*rfm));
186    if (!rfm) {
187        BERR_TRACE(NEXUS_OUT_OF_SYSTEM_MEMORY);
188        return NULL;
189    }
190    BKNI_Memset(rfm, 0, sizeof(*rfm));
191    BDBG_OBJECT_SET(rfm, NEXUS_Rfm);
192    rfm->index = index;
193
194    NEXUS_VIDEO_OUTPUT_INIT(&rfm->videoOutput, NEXUS_VideoOutputType_eRfm, rfm);
195    NEXUS_AUDIO_OUTPUT_INIT(&rfm->audioOutput, NEXUS_AudioOutputType_eRfm, rfm);
196    rfm->audioOutput.port = NEXUS_AudioOutputPort_eRfMod;
197
198    rc = BRFM_GetDefaultSettings(&rfmSettings, g_pCoreHandles->chp);
199    if (rc) {rc = BERR_TRACE(rc); goto error;}
200    rfmSettings.volume = pSettings->volume/100;
201
202    rc = BRFM_Open(&rfm->mRfm, g_pCoreHandles->chp, g_pCoreHandles->reg, g_pCoreHandles->bint, &rfmSettings);
203    if (rc) {rc = BERR_TRACE(rc); goto error;}
204
205    rc = NEXUS_Rfm_SetSettings(rfm, pSettings);
206    if (rc) {rc = BERR_TRACE(rc); goto error;}
207
208    g_NEXUS_rfmHandle[index] = rfm;
209    return rfm;
210
211error:
212    NEXUS_Rfm_Close(rfm);
213    return NULL;
214}
215
216void NEXUS_Rfm_Close( NEXUS_RfmHandle rfm )
217{
218    BDBG_OBJECT_ASSERT(rfm, NEXUS_Rfm);
219
220    if (rfm->mRfm) {
221        BRFM_Close(rfm->mRfm);
222    }
223
224    BDBG_OBJECT_DESTROY(rfm, NEXUS_Rfm);
225    BKNI_Free(rfm);
226}
227
228void NEXUS_Rfm_GetSettings( NEXUS_RfmHandle rfm, NEXUS_RfmSettings *pSettings )
229{
230    BDBG_OBJECT_ASSERT(rfm, NEXUS_Rfm);
231    *pSettings = rfm->settings;
232}
233
234NEXUS_Error NEXUS_Rfm_SetSettings( NEXUS_RfmHandle rfm, const NEXUS_RfmSettings *pSettings )
235{
236    NEXUS_Error rc;
237
238    BDBG_OBJECT_ASSERT(rfm, NEXUS_Rfm);
239
240    /* save the settings first, then call the internal set function */
241    if ( rfm->settings.volume != pSettings->volume )
242    {
243        rfm->volumeChanged = true;
244    }
245    rfm->settings = *pSettings;
246
247    rc = NEXUS_Rfm_SetConnectionSettings_priv(rfm, &rfm->connectionSettings);
248    if (rc) return BERR_TRACE(rc);
249
250    return 0;
251}
252
253NEXUS_VideoOutput NEXUS_Rfm_GetVideoConnector( NEXUS_RfmHandle rfm )
254{
255    BDBG_OBJECT_ASSERT(rfm, NEXUS_Rfm);
256    return &rfm->videoOutput;
257}
258
259NEXUS_AudioOutput NEXUS_Rfm_GetAudioConnector( NEXUS_RfmHandle rfm )
260{
261    BDBG_OBJECT_ASSERT(rfm, NEXUS_Rfm);
262    return &rfm->audioOutput;
263}
264
265void NEXUS_Rfm_GetIndex_priv( NEXUS_RfmHandle rfm, unsigned *pIndex )
266{
267    BDBG_OBJECT_ASSERT(rfm, NEXUS_Rfm);
268    NEXUS_ASSERT_MODULE();
269    *pIndex = rfm->index;
270}
271
272void NEXUS_Rfm_GetConnectionSettings_priv( NEXUS_RfmHandle rfm, NEXUS_RfmConnectionSettings *pSettings )
273{
274    BDBG_OBJECT_ASSERT(rfm, NEXUS_Rfm);
275    NEXUS_ASSERT_MODULE();
276    *pSettings = rfm->connectionSettings;
277}
278
279/* This function combines the user Settings and the internal ConnectionSettings and
280applies them to RFM PI */
281NEXUS_Error NEXUS_Rfm_SetConnectionSettings_priv( NEXUS_RfmHandle rfm, const NEXUS_RfmConnectionSettings *pSettings )
282{
283    BRFM_ModulationType modType;
284    BRFM_OutputChannel chNbr;
285    BERR_Code rc;
286
287    BDBG_OBJECT_ASSERT(rfm, NEXUS_Rfm);
288    NEXUS_ASSERT_MODULE();
289
290    /* We do not call BRFM_SetAudioVolume for 74xx.
291    74xx chips change vol via the mixer thereby affecting dac volume and RFM volume downstream.
292    7038 based systems, do not use mixer to change vol, hence it would need RFM vol control here. */
293
294    if (pSettings->audioEnabled) {
295        rc = BRFM_SetAudioMute(rfm->mRfm, rfm->settings.muted || !pSettings->audioEnabled);
296        if (rc) return BERR_TRACE(rc);
297        if ( rfm->volumeChanged )
298        {
299            rc = BRFM_SetAudioVolume(rfm->mRfm, rfm->settings.volume/100);
300            if (rc) return BERR_TRACE(rc);
301            rfm->volumeChanged = false;
302        }
303    }
304
305    switch (rfm->settings.channel) {
306    case 3: chNbr = BRFM_OutputChannel_eCh3; break;
307    case 4: chNbr = BRFM_OutputChannel_eCh4; break;
308    default: return BERR_TRACE(BERR_INVALID_PARAMETER);
309    }
310
311    switch (pSettings->videoFormat) {
312    case NEXUS_VideoFormat_eSecam:
313        modType = BRFM_ModulationType_eSecamBG;
314        break;
315    case NEXUS_VideoFormat_ePalG:
316    case NEXUS_VideoFormat_ePalB:
317    case NEXUS_VideoFormat_ePalB1:
318        modType = BRFM_ModulationType_ePalBG;
319        break;
320    case NEXUS_VideoFormat_ePalH:
321    case NEXUS_VideoFormat_ePalK: /* TODO: is this right? */
322        modType = BRFM_ModulationType_ePalH;
323        break;
324    case NEXUS_VideoFormat_ePalI:
325        modType = BRFM_ModulationType_ePalI;
326        break;
327    case NEXUS_VideoFormat_ePalM:
328        modType = BRFM_ModulationType_ePalM;
329        break;
330    case NEXUS_VideoFormat_ePalN:
331    case NEXUS_VideoFormat_ePalNc:
332        modType = BRFM_ModulationType_ePalN;
333        break;
334    case NEXUS_VideoFormat_ePalD:
335        modType = BRFM_ModulationType_ePalDChina;
336        break;
337    case NEXUS_VideoFormat_ePalD1:
338        modType = BRFM_ModulationType_ePalD;
339        break;
340    default:
341        modType = BRFM_ModulationType_eNtscOpenCable;
342        break;
343#if 0
344/* unused RFM enums */
345        modType = BRFM_ModulationType_eNtscCustom;
346        modType = BRFM_ModulationType_ePalCustom;
347        modType = BRFM_ModulationType_eSecamDK;
348        modType = BRFM_ModulationType_eSecamK1;
349#endif
350    }
351
352    if (pSettings->videoEnabled || pSettings->audioEnabled) {
353        rc = BRFM_SetModulationType(rfm->mRfm, modType, chNbr);
354        if (rc) return BERR_TRACE(rc);
355    }
356    else {
357        rc = BRFM_DisableRfOutput(rfm->mRfm);
358        if (rc) return BERR_TRACE(rc);
359        rc = BRFM_EnablePowerSaver(rfm->mRfm);
360        if (rc) return BERR_TRACE(rc);
361    }
362
363    rfm->connectionSettings = *pSettings;
364
365    return 0;
366}
367
368NEXUS_Error NEXUS_RfmModule_Standby_priv( bool enabled, const NEXUS_StandbySettings *pSettings )
369{
370#if NEXUS_POWER_MANAGEMENT
371    BERR_Code rc;
372    unsigned i;
373    NEXUS_RfmHandle rfm = NULL;
374    BSTD_UNUSED(pSettings);
375   
376    for (i=0; i<NEXUS_NUM_RFM_OUTPUTS; i++) {
377        if ( (rfm = g_NEXUS_rfmHandle[i]) ) {
378            if (enabled) { /* means that we have to power down in one way or another */
379                if (pSettings->mode != NEXUS_StandbyMode_eDeepSleep) { /* not S3 */
380                    rc = BRFM_Standby(rfm->mRfm);
381                    if (rc) { return BERR_TRACE(NEXUS_UNKNOWN); }
382                }
383                else {
384                    BRFM_Close(rfm->mRfm);
385                    rfm->mRfm = NULL;
386                }
387            }
388            else { /* resume, using the opposite call */
389                if (rfm->mRfm) {
390                    BRFM_Resume(rfm->mRfm);
391                }
392                else {
393                    BRFM_Settings rfmSettings;
394                    rc = BRFM_GetDefaultSettings(&rfmSettings, g_pCoreHandles->chp);
395                    if (rc) { return BERR_TRACE(NEXUS_UNKNOWN); }
396
397                    rc = BRFM_Open(&rfm->mRfm, g_pCoreHandles->chp, g_pCoreHandles->reg, g_pCoreHandles->bint, &rfmSettings);
398                    if (rc) { return BERR_TRACE(NEXUS_UNKNOWN); }
399
400                    rc = NEXUS_Rfm_SetSettings(rfm, &rfm->settings);
401                    if (rc) { return BERR_TRACE(NEXUS_UNKNOWN); }
402                }
403            }           
404        }
405    }
406   
407    return NEXUS_SUCCESS;   
408#else
409    BSTD_UNUSED(pSettings);
410    BSTD_UNUSED(enabled);
411    return NEXUS_SUCCESS;
412#endif
413}
414
Note: See TracBrowser for help on using the repository browser.