summaryrefslogtreecommitdiff
path: root/drivers/staging/nmf-cm/cm/engine/power_mgt/src/cmpower.c
blob: a104486db6cddb58570e6df5a65543fa731a874a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*
 * Copyright (C) ST-Ericsson SA 2010
 * Author: Jean-Philippe FASSINO <jean-philippe.fassino@stericsson.com> for ST-Ericsson.
 * License terms: GNU General Public License (GPL) version 2.
 */
#include "../inc/power.h"

#include <cm/engine/os_adaptation_layer/inc/os_adaptation_layer.h>
#include <cm/engine/trace/inc/trace.h>
#include <cm/engine/utils/inc/convert.h>
#include <cm/engine/dsp/inc/dsp.h>
#include <cm/engine/executive_engine_mgt/inc/executive_engine_mgt.h>

// -------------------------------------------------------------------------------
// Compilation flags
// -------------------------------------------------------------------------------
#define __PWR_DEBUG_TRACE_LEVEL 2  					// Debug trave level for CM power module

// -------------------------------------------------------------------------------
// Internal counter to store the TCM allocated chunk (by MPC)
// -------------------------------------------------------------------------------
static t_uint32 _pwrMPCHWIPCountT[NB_CORE_IDS];

// -------------------------------------------------------------------------------
// Internal counter to store the TCM allocated chunk (by MPC)
// -------------------------------------------------------------------------------
static t_uint32 _pwrMPCMemoryCountT[NB_CORE_IDS];


// -------------------------------------------------------------------------------
// Internal data to store the global Power Manager mode (see cm_PWR_Init fct)
// -------------------------------------------------------------------------------
t_nmf_power_mode powerMode = NORMAL_PWR_MODE;

// -------------------------------------------------------------------------------
// cm_PWR_Init
// -------------------------------------------------------------------------------
PUBLIC t_cm_error cm_PWR_Init(void)
{
	int i;

	for (i=0; i<NB_CORE_IDS;i++)
	{
        _pwrMPCHWIPCountT[i] = 0;
        _pwrMPCMemoryCountT[i] = 0;
	}

	return CM_OK;
}

// -------------------------------------------------------------------------------
// cm_PWR_SetMode
// -------------------------------------------------------------------------------
void cm_PWR_SetMode(t_nmf_power_mode aMode)
{
	powerMode = aMode;
}

t_nmf_power_mode cm_PWR_GetMode()
{
    return powerMode;
}

t_uint32 cm_PWR_GetMPCMemoryCount(t_nmf_core_id coreId)
{
    return _pwrMPCMemoryCountT[coreId];
}


PUBLIC t_cm_error cm_PWR_EnableMPC(
        t_mpc_power_request             request,
        t_nmf_core_id                   coreId)
{
    t_cm_error error;

    switch(request)
    {
    case MPC_PWR_CLOCK:
        LOG_INTERNAL(__PWR_DEBUG_TRACE_LEVEL, "[Pwr] MPC %s enable clock\n", cm_getDspName(coreId), 0, 0, 0, 0, 0);
        if((error = OSAL_EnablePwrRessource(CM_OSAL_POWER_SxA_CLOCK, coreId, 0)) != CM_OK)
        {
            ERROR("[Pwr] MPC %s clock can't be enabled\n", cm_getDspName(coreId), 0, 0, 0, 0, 0);
            return error;
        }
        break;
    case MPC_PWR_AUTOIDLE:
        if((error = OSAL_EnablePwrRessource(CM_OSAL_POWER_SxA_AUTOIDLE, coreId, 0)) != CM_OK)
        {
            ERROR("[Pwr] MPC %s clock can't be auto-idle\n", cm_getDspName(coreId), 0, 0, 0, 0, 0);
            return error;
        }
        break;
    case MPC_PWR_HWIP:
        if(_pwrMPCHWIPCountT[coreId]++ == 0)
        {
            LOG_INTERNAL(__PWR_DEBUG_TRACE_LEVEL, "[Pwr] MPC %s HW IP enable clock\n",cm_getDspName(coreId), 0, 0, 0, 0, 0);

            // The PRCMU seem not supporting the transition of asking HW IP on while DSP in retention
            // -> Thus force wake up of the MMDSP before asking the transition
            if ((error = cm_EEM_ForceWakeup(coreId)) != CM_OK)
                return error;

            if((error = OSAL_EnablePwrRessource(CM_OSAL_POWER_SxA_HARDWARE, coreId, 0)) != CM_OK)
            {
                ERROR("[Pwr] MPC %s HW IP clock can't be enabled\n", cm_getDspName(coreId), 0, 0, 0, 0, 0);
                cm_EEM_AllowSleep(coreId);
                return error;
            }

            cm_EEM_AllowSleep(coreId);
        }
        break;
    }

    return CM_OK;
}

PUBLIC void cm_PWR_DisableMPC(
        t_mpc_power_request             request,
        t_nmf_core_id                   coreId)
{
    switch(request)
    {
    case MPC_PWR_CLOCK:
        LOG_INTERNAL(__PWR_DEBUG_TRACE_LEVEL, "[Pwr] MPC %s disable clock\n",cm_getDspName(coreId), 0, 0, 0, 0, 0);
        OSAL_DisablePwrRessource(CM_OSAL_POWER_SxA_CLOCK, coreId, 0);
        break;
    case MPC_PWR_AUTOIDLE:
        OSAL_DisablePwrRessource(CM_OSAL_POWER_SxA_AUTOIDLE, coreId, 0);
        break;
    case MPC_PWR_HWIP:
        if(--_pwrMPCHWIPCountT[coreId] == 0)
        {
            LOG_INTERNAL(__PWR_DEBUG_TRACE_LEVEL, "[Pwr] MPC %s HW IP disable clock\n",cm_getDspName(coreId), 0, 0, 0, 0, 0);

            // The PRCMU seem not supporting the transition of asking HW IP on while DSP in retention
            // -> Thus force wake up of the MMDSP before asking the transition
            if (cm_EEM_ForceWakeup(coreId) != CM_OK)
                return;

            OSAL_DisablePwrRessource(CM_OSAL_POWER_SxA_HARDWARE, coreId, 0);

            cm_EEM_AllowSleep(coreId);
        }
        break;
    }
}

PUBLIC t_cm_error cm_PWR_EnableHSEM(void)
{
    t_cm_error error;

    LOG_INTERNAL(__PWR_DEBUG_TRACE_LEVEL, "[Pwr] HSEM enable clock\n",0 , 0, 0, 0, 0, 0);
    if((error = OSAL_EnablePwrRessource(CM_OSAL_POWER_HSEM, 0, 0)) != CM_OK)
    {
        ERROR("[Pwr] HSEM clock can't be enabled\n", 0, 0, 0, 0, 0, 0);
        return error;
    }

    return CM_OK;
}

PUBLIC void cm_PWR_DisableHSEM(void)
{
    LOG_INTERNAL(__PWR_DEBUG_TRACE_LEVEL, "[Pwr] HSEM disable clock\n",0 , 0, 0, 0, 0, 0);
    OSAL_DisablePwrRessource(CM_OSAL_POWER_HSEM, 0, 0);
}

PUBLIC t_cm_error cm_PWR_EnableMemory(
        t_nmf_core_id                   coreId,
        t_dsp_memory_type_id            dspMemType,
        t_cm_physical_address           address,
        t_cm_size                       size)
{
    switch(dspMemType)
    {
    case INTERNAL_XRAM24:
    case INTERNAL_XRAM16:
    case INTERNAL_YRAM24:
    case INTERNAL_YRAM16:
        _pwrMPCMemoryCountT[coreId]++;
        break;
    case SDRAM_EXT24:
    case SDRAM_EXT16:
    case SDRAM_CODE:
    case LOCKED_CODE:
        return OSAL_EnablePwrRessource(
                CM_OSAL_POWER_SDRAM,
                address,
                size);
    case ESRAM_EXT24:
    case ESRAM_EXT16:
    case ESRAM_CODE:
        return OSAL_EnablePwrRessource(
                CM_OSAL_POWER_ESRAM,
                address,
                size);
    default:
	    CM_ASSERT(0);
    }

    return CM_OK;
}

PUBLIC void cm_PWR_DisableMemory(
        t_nmf_core_id                   coreId,
        t_dsp_memory_type_id            dspMemType,
        t_cm_physical_address           address,
        t_cm_size                       size)
{
    switch(dspMemType)
    {
    case INTERNAL_XRAM24:
    case INTERNAL_XRAM16:
    case INTERNAL_YRAM24:
    case INTERNAL_YRAM16:
        _pwrMPCMemoryCountT[coreId]--;
        break;
    case SDRAM_EXT24:
    case SDRAM_EXT16:
    case SDRAM_CODE:
    case LOCKED_CODE:
        OSAL_DisablePwrRessource(
                CM_OSAL_POWER_SDRAM,
                address,
                size);
        break;
    case ESRAM_EXT24:
    case ESRAM_EXT16:
    case ESRAM_CODE:
        OSAL_DisablePwrRessource(
                CM_OSAL_POWER_ESRAM,
                address,
                size);
        break;
    default:
	    CM_ASSERT(0);
    }
}