/*************************************************************************** * Copyright (c) 2003-2010, Broadcom Corporation * All Rights Reserved * Confidential Property of Broadcom Corporation * * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. * * $brcm_Workfile: bpwr.c $ * $brcm_Revision: Hydra_Software_Devel/1 $ * $brcm_Date: 11/23/10 2:10p $ * * Module Description: * * Revision History: * * $brcm_Log: /magnum/portinginterface/pwr/7552/bpwr.c $ * * Hydra_Software_Devel/1 11/23/10 2:10p xhuang * SW7552-9: Add support for 97552 * * ***************************************************************************/ #include "bstd.h" /* standard types */ #include "berr.h" #include "bstd_ids.h" #include "bdbg.h" /* Dbglib */ #include "bkni.h" /* malloc */ #include "bpwr.h" #include "bpwr_mem.h" #include "bpwr_priv.h" BDBG_MODULE(BPWR); BDBG_OBJECT_ID(BPWR_P_Context); BERR_Code BPWR_GetDefaultSettings(BPWR_Settings *pDefSettings ) { BKNI_Memset(pDefSettings, 0, sizeof(*pDefSettings)); return BERR_SUCCESS; } /*************************************************************************** * BPWR_Open() * * Create Power Management Object * */ BERR_Code BPWR_Open ( BPWR_Handle *phPwr, BCHP_Handle hChip, BREG_Handle hRegister, const BPWR_Settings *pDefSettings ) { BPWR_P_Context *pPwr; BERR_Code eStatus = BERR_SUCCESS; BDBG_ENTER(BPWR_Open); BDBG_ASSERT(hRegister); #if 0 BDBG_SetLevel(BDBG_eMsg); BDBG_SetModuleLevel("BPWR", BDBG_eMsg); #endif /* The handle will be NULL if create fails. */ *phPwr = NULL; /* check PWR settings */ /* Alloc the main PWR context. */ pPwr = (BPWR_P_Context*)(BKNI_Malloc(sizeof(BPWR_P_Context))); if(!pPwr) { BERR_TRACE(eStatus = BERR_OUT_OF_SYSTEM_MEMORY); goto done; } /* Clear out the context and set defaults. */ BKNI_Memset((void*)pPwr, 0x0, sizeof(BPWR_P_Context)); BDBG_OBJECT_SET(pPwr, BPWR_P_Context); /* Store the hRegister and hChip for later use. */ pPwr->hChip = hChip; pPwr->hRegister = hRegister; pPwr->changeMode = BPWR_Mode_ePowerUndefined; /* Take in default settings. */ if (pDefSettings) { pPwr->stSettings = *pDefSettings; } else { BPWR_GetDefaultSettings(&pPwr->stSettings); pDefSettings = &pPwr->stSettings; } /* Allocate and initialize module*/ eStatus = BPWR_P_Init(pPwr); if (eStatus != BERR_SUCCESS) { BKNI_Free((void *)pPwr); goto done; } /* All done. now return the new fresh context to user. */ *phPwr = (BPWR_Handle)pPwr; done: BDBG_LEAVE(BPWR_Open); return eStatus; } /*************************************************************************** * */ BERR_Code BPWR_Close ( BPWR_Handle hPwr ) { BDBG_ENTER(BPWR_Close); BDBG_OBJECT_ASSERT(hPwr, BPWR_P_Context); BPWR_P_Destroy(hPwr); BKNI_Free(hPwr); BDBG_LEAVE(BPWR_Close); return BERR_SUCCESS; } /*************************************************************************** * */ BERR_Code BPWR_SetMode ( BPWR_Handle hPwr, BSTD_Module module, BPWR_ePowerMode eMode ) { unsigned i; BDBG_OBJECT_ASSERT(hPwr, BPWR_P_Context); BDBG_ASSERT(eMode != BPWR_Mode_ePowerUndefined); if (eMode == BPWR_Mode_ePowerUndefined) { /* can't set to undefined */ return BERR_TRACE(BERR_INVALID_PARAMETER); } else if (hPwr->changeMode == BPWR_Mode_ePowerUndefined) { /* this is the first Set */ hPwr->changeMode = eMode; } else if (hPwr->changeMode != eMode) { /* this is an invalid mixed set */ BDBG_ERR(("Cannot both power up and down in one apply changes set")); return BERR_TRACE(BERR_INVALID_PARAMETER); } for (i=0;imodules[i].moduleId == module) { hPwr->modules[i].change = true; return 0; } } BDBG_WRN(("Module %d is not supported on this chip", module)); return -1; /* no BERR_TRACE */ } /*************************************************************************** * */ BERR_Code BPWR_GetMode ( const BPWR_Handle hPwr, BSTD_Module module, BPWR_ePowerMode *peMode ) { unsigned i; BDBG_OBJECT_ASSERT(hPwr, BPWR_P_Context); for(i=0; imodules[i].moduleId == module) { *peMode = hPwr->modules[i].mode; return 0; } } return BERR_TRACE(BERR_INVALID_PARAMETER); } /*************************************************************************** * */ BERR_Code BPWR_GetModuleCount ( BPWR_Handle hPwr, uint32_t *pulModuleCount ) { unsigned i; BDBG_ENTER(BPWR_GetModuleCount); BDBG_OBJECT_ASSERT(hPwr, BPWR_P_Context); *pulModuleCount = 0; for(i=0; imodules[i].moduleId) { (*pulModuleCount)++; } } BDBG_WRN(("Number of modules: %d", *pulModuleCount)); BDBG_LEAVE(BPWR_GetModuleCount); return 0; } /*************************************************************************** * */ BERR_Code BPWR_GetModuleList ( BPWR_Handle hPwr, BSTD_Module *pModuleList, unsigned ulModuleCount ) { unsigned i, total = 0; BDBG_ENTER(BPWR_GetModuleList); BDBG_OBJECT_ASSERT(hPwr, BPWR_P_Context); for(i=0; imodules[i].moduleId) { pModuleList[total++] = hPwr->modules[i].moduleId; } } BDBG_LEAVE(BPWR_GetModuleList); return 0; } /*************************************************************************** * */ BERR_Code BPWR_SetModes ( BPWR_Handle hPwr, BSTD_Module *pModuleList, uint32_t ulModuleCount, BPWR_ePowerMode eMode ) { unsigned i; BDBG_ENTER(BPWR_SetModes); BDBG_OBJECT_ASSERT(hPwr, BPWR_P_Context); for (i=0;imodules[i].change) { #if 1 hPwr->modules[i].change = false; #else /* this is a way of verifying that every module id listed has some PWR code associated */ BDBG_ERR(("PWR unable to make requested change to module %d", hPwr->modules[i].moduleId)); rc = BERR_TRACE(BERR_UNKNOWN); #endif } } hPwr->changeMode = BPWR_Mode_ePowerUndefined; return rc; }