[processor-sdk/performance-audio-sr.git] / psdk_cust / pdk_k2g_1_0_1_2_eng / packages / ti / board / src / evmKeystone / board_clock.c
1 /******************************************************************************
2 * Copyright (c) 2015 Texas Instruments Incorporated - http://www.ti.com
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the
14 * distribution.
15 *
16 * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 *****************************************************************************/
34 #include "board_internal.h"
35 #include "board_clock.h"
37 static bool set_psc_state(uint32_t domainNum, uint32_t moduleNum, CSL_PSC_MODSTATE state)
38 {
39 uint32_t timeoutCnt = 5;
41 /* If state already set, do nothing */
42 if (CSL_FEXT(hPscRegs->MDSTAT[moduleNum], PSC_MDSTAT_STATE) == state)
43 return true;
45 if (state == PSC_MODSTATE_ENABLE)
46 CSL_PSC_enablePowerDomain(domainNum);
48 /* Enable the clock for the module */
49 CSL_PSC_setModuleNextState(moduleNum, state);
51 /* Start the state transition */
52 CSL_PSC_startStateTransition(domainNum);
54 /* Wait until the state transition process is completed. */
55 while (!CSL_PSC_isStateTransitionDone(domainNum)) {
56 BOARD_delay(1);
57 timeoutCnt--;
58 if (timeoutCnt == 0)
59 return false;
60 }
62 return true;
63 }
65 Board_STATUS Board_moduleClockInit()
66 {
67 uint32_t i;
68 uint32_t numConfigs;
70 numConfigs = Board_getNumPSCconfigs();
72 for (i = 0; i < numConfigs; i++) {
73 if (set_psc_state(pscConfigs[i].domainNum, pscConfigs[i].moduleNum, PSC_MODSTATE_ENABLE) == false)
74 return BOARD_INIT_CLOCK_FAIL;
75 }
77 return BOARD_SOK;
78 }