1 /****************************************************************************
2 **+-----------------------------------------------------------------------+**
3 **| |**
4 **| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved. |**
5 **| All rights reserved. |**
6 **| |**
7 **| Redistribution and use in source and binary forms, with or without |**
8 **| modification, are permitted provided that the following conditions |**
9 **| are met: |**
10 **| |**
11 **| * Redistributions of source code must retain the above copyright |**
12 **| notice, this list of conditions and the following disclaimer. |**
13 **| * Redistributions in binary form must reproduce the above copyright |**
14 **| notice, this list of conditions and the following disclaimer in |**
15 **| the documentation and/or other materials provided with the |**
16 **| distribution. |**
17 **| * Neither the name Texas Instruments nor the names of its |**
18 **| contributors may be used to endorse or promote products derived |**
19 **| from this software without specific prior written permission. |**
20 **| |**
21 **| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |**
22 **| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |**
23 **| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |**
24 **| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |**
25 **| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |**
26 **| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |**
27 **| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |**
28 **| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |**
29 **| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |**
30 **| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |**
31 **| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |**
32 **| |**
33 **+-----------------------------------------------------------------------+**
34 ****************************************************************************/
35
36 /**********************************************************************************/
37 /* */
38 /* MODULE: PowerAuthorization.c */
39 /* PURPOSE: PowerAuthorization implementation module */
40 /* */
41 /**********************************************************************************/
42 #include "whalCtrl_api.h"
43 #include "report.h"
44 #include "MacServices_api.h"
45 #include "MacServices.h"
46 #include "PowerAuthorization.h"
47 #include "PowerAuthorization_internal.h"
48
49 /****************************************************************************
50 * powerAutho_Create()
51 ****************************************************************************
52 * DESCRIPTION:
53 *
54 * INPUTS: hOs - the handle to the OS layer
55 * hReport - the handle to the report module
56 * hELPCtrl - the handle to the ELPCtrl module
57 *
58 *
59 * OUTPUT: the context of the PowerAuthorization module
60 *
61 * RETURNS: the context of the PowerAuthorization module (NULL if error)
62 ****************************************************************************/
powerAutho_Create(TI_HANDLE hOs)63 TI_HANDLE powerAutho_Create(TI_HANDLE hOs)
64 {
65 powerAutho_t *pObj;
66
67 pObj = os_memoryAlloc(hOs, sizeof(powerAutho_t));
68 if (pObj == NULL)
69 {
70 WLAN_OS_REPORT(("FATAL ERROR: powerAutho_Create(): Error allocating context\n"));
71 return NULL;
72 }
73
74 os_memoryZero(hOs, pObj, sizeof(powerAutho_t));
75
76 pObj->hOs = hOs;
77 pObj->hReport = NULL;
78 pObj->hHalCtrl = NULL;
79
80 /* set as 'before init complete' */
81 pObj->initComplete = FALSE;
82
83 pObj->m_AwakeRequired = 0;
84 pObj->m_PowerPolicy = POWERAUTHO_POLICY_PD;
85 pObj->m_MinPowerLevel = POWERAUTHO_POLICY_PD;
86
87 return pObj;
88 }
89
90
91 /****************************************************************************
92 * powerAutho_Destroy()
93 ****************************************************************************
94 * DESCRIPTION:
95 *
96 * INPUTS: hPowerAutho - the handle to the PowerAuthorization module.
97 *
98 *
99 * OUTPUT:
100 *
101 * RETURNS: OK
102 ****************************************************************************/
powerAutho_Destroy(TI_HANDLE hPowerAutho)103 int powerAutho_Destroy(TI_HANDLE hPowerAutho)
104 {
105 powerAutho_t *pPowerAutho = (powerAutho_t*)hPowerAutho;
106
107 if (pPowerAutho)
108 os_memoryFree(pPowerAutho->hOs, pPowerAutho, sizeof(powerAutho_t));
109
110 return OK;
111 }
112
113 /****************************************************************************
114 * powerAutho_Configure()
115 ****************************************************************************
116 * DESCRIPTION:
117 *
118 * INPUTS: hPowerAutho - the handle to the PowerAuthorization module.
119 * aPowerPolicy - the power policy to configure.
120 *
121 *
122 * OUTPUT:
123 *
124 * RETURNS: OK
125 ****************************************************************************/
powerAutho_Configure(TI_HANDLE hPowerAutho,TI_HANDLE hReport,TI_HANDLE hHalCtrl,powerAutho_PowerPolicy_e aPowerPolicy)126 int powerAutho_Configure(TI_HANDLE hPowerAutho, TI_HANDLE hReport, TI_HANDLE hHalCtrl, powerAutho_PowerPolicy_e aPowerPolicy)
127 {
128 powerAutho_t *pPowerAutho = (powerAutho_t*)hPowerAutho;
129
130 pPowerAutho->m_PowerPolicy = aPowerPolicy;
131
132 pPowerAutho->m_ElpCtrl_Mode_LUT[POWERAUTHO_POLICY_AWAKE] = ELPCTRL_MODE_KEEP_AWAKE;
133 pPowerAutho->m_ElpCtrl_Mode_LUT[POWERAUTHO_POLICY_PD] = ELPCTRL_MODE_KEEP_AWAKE;
134 pPowerAutho->m_ElpCtrl_Mode_LUT[POWERAUTHO_POLICY_ELP] = ELPCTRL_MODE_NORMAL;
135
136 pPowerAutho->hReport = hReport;
137 pPowerAutho->hHalCtrl = hHalCtrl;
138
139 return OK;
140 }
141
142 /****************************************************************************
143 * powerAutho_PowerPolicyUpdate()
144 ****************************************************************************
145 * DESCRIPTION: updates the PowerPolicy and calcs the new MinPowerPolicy of the sustem
146 *
147 * INPUTS: hMacServices - the handle to the MacServices module.
148 * aPowerPolicy - the new power policy.
149 *
150 *
151 * OUTPUT: none
152 *
153 * RETURNS: OK or NOK
154 ****************************************************************************/
MacServices_powerAutho_PowerPolicyUpdate(TI_HANDLE hMacServices,powerAutho_PowerPolicy_e aPowerPolicy)155 int MacServices_powerAutho_PowerPolicyUpdate(TI_HANDLE hMacServices, powerAutho_PowerPolicy_e aPowerPolicy)
156 {
157 powerAutho_t *pPowerAutho = (powerAutho_t*)(((MacServices_t*)hMacServices)->hPowerAutho);
158
159 WLAN_REPORT_INFORMATION (pPowerAutho->hReport,ELP_MODULE_LOG,
160 ("MacServices_powerAutho_PowerPolicyUpdate: PowerPolicy = %d\n",aPowerPolicy));
161
162 pPowerAutho->m_PowerPolicy = aPowerPolicy;
163
164 return powerAutho_CalcMinPowerLevel(pPowerAutho);
165 }
166
167 /****************************************************************************
168 * powerAutho_AwakeRequiredUpdate()
169 ****************************************************************************
170 * DESCRIPTION: updates the AwakeRequired and calcs the new MinPowerPolicy of the sustem
171 *
172 * INPUTS: hMacServices - the handle to the MacServices module.
173 * aAwakeRequired - the awake required parameter,
174 * can be according to the enum required or not_required.
175 * aAwakeReason - the reason that the HW is required
176 *
177 * OUTPUT: none
178 *
179 * RETURNS: OK or NOK
180 ****************************************************************************/
MacServices_powerAutho_AwakeRequiredUpdate(TI_HANDLE hMacServices,MacServices_powerAutho_AwakeRequired_e aAwakeRequired,MacServices_powerAutho_AwakeReason_e aAwakeReason)181 int MacServices_powerAutho_AwakeRequiredUpdate(TI_HANDLE hMacServices, MacServices_powerAutho_AwakeRequired_e aAwakeRequired, MacServices_powerAutho_AwakeReason_e aAwakeReason)
182 {
183 powerAutho_t *pPowerAutho = (powerAutho_t*)(((MacServices_t*)hMacServices)->hPowerAutho);
184
185 if(aAwakeRequired == POWERAUTHO_AWAKE_REQUIRED)
186 {
187 pPowerAutho->m_AwakeRequired |= (1<<aAwakeReason);
188 }
189 else
190 { /* aAwakeRequired == POWERAUTHO_AWAKE_NOT_REQUIRED*/
191 pPowerAutho->m_AwakeRequired &= ~(1<<aAwakeReason);
192 }
193
194 WLAN_REPORT_INFORMATION (pPowerAutho->hReport,ELP_MODULE_LOG,
195 ("MacServices_powerAutho_AwakeRequiredUpdate: awake required sent %d (reason %d) and the updated is %d\n", aAwakeRequired, aAwakeReason, pPowerAutho->m_AwakeRequired));
196
197 return powerAutho_CalcMinPowerLevel(pPowerAutho);
198 }
199
200 /****************************************************************************
201 * powerAutho_CalcMinPowerLevel()
202 ****************************************************************************
203 * DESCRIPTION: calculate the min power level
204 *
205 * INPUTS: hPowerAutho - the handle to the PowerAuthorization module.
206 *
207 * OUTPUT: none
208 *
209 * RETURNS: OK or NOK
210 ****************************************************************************/
powerAutho_CalcMinPowerLevel(TI_HANDLE hPowerAutho)211 int powerAutho_CalcMinPowerLevel(TI_HANDLE hPowerAutho)
212 {
213 powerAutho_t *pPowerAutho = (powerAutho_t*)hPowerAutho;
214 powerAutho_PowerPolicy_e newMinPowerLevel;
215
216 /* calc the new MinPowerLevel */
217 if(pPowerAutho->m_AwakeRequired > 0)
218 newMinPowerLevel = POWERAUTHO_POLICY_AWAKE;
219 else
220 newMinPowerLevel = pPowerAutho->m_PowerPolicy;
221
222 /* check if the MinPowerLevel changed */
223 if(pPowerAutho->m_MinPowerLevel != newMinPowerLevel)
224 {
225 WLAN_REPORT_INFORMATION (pPowerAutho->hReport,ELP_MODULE_LOG,
226 ("powerAutho_CalcMinPowerLevel - new MinPowerLevel is = %d\n",newMinPowerLevel));
227
228 pPowerAutho->m_MinPowerLevel = newMinPowerLevel;
229
230 /* we do the update of the FW only after the init complete*/
231 if(pPowerAutho->initComplete == TRUE)
232 {
233 /* Update interface mode */
234 whalCtrl_ElpCtrl_SetMode(pPowerAutho->hHalCtrl, pPowerAutho->m_ElpCtrl_Mode_LUT[newMinPowerLevel]);
235
236 /* Send MIB with PowerPolicy */
237 whalCtrl_SetMinPowerLevel(pPowerAutho->hHalCtrl, newMinPowerLevel);
238 return OK;
239 }
240 }
241
242 return TNETWIF_COMPLETE;
243 }
244
245 /****************************************************************************
246 * powerAutho_PowerPolicyUpdate()
247 ****************************************************************************
248 * DESCRIPTION: send the min power level to the FW for the first time
249 *
250 * INPUTS: hMacServices - the handle to the MacServices module.
251 *
252 *
253 * OUTPUT: none
254 *
255 * RETURNS: OK or NOK
256 ****************************************************************************/
MacServices_powerAutho_ExitFromInit(TI_HANDLE hMacServices)257 int MacServices_powerAutho_ExitFromInit(TI_HANDLE hMacServices)
258 {
259 powerAutho_t *pPowerAutho = (powerAutho_t*)(((MacServices_t*)hMacServices)->hPowerAutho);
260 whalParamInfo_t ParamInfo;
261
262 WLAN_REPORT_INFORMATION (pPowerAutho->hReport,ELP_MODULE_LOG,
263 ("MacServices_powerAutho_ExitFromInit: PowerPolicy = %d\n",pPowerAutho->m_MinPowerLevel ));
264 /* set as 'after init complete' */
265 pPowerAutho->initComplete = TRUE;
266
267 /* Update interface mode */
268 whalCtrl_ElpCtrl_SetMode(pPowerAutho->hHalCtrl, pPowerAutho->m_ElpCtrl_Mode_LUT[pPowerAutho->m_MinPowerLevel]);
269
270 /* Send MIB with PowerPolicy */
271 ParamInfo.paramType = (UINT32)HAL_CTRL_MIN_POWER_LEVEL;
272 ParamInfo.paramLength = sizeof(powerAutho_PowerPolicy_e);
273 ParamInfo.content.minPowerPolicy = pPowerAutho->m_MinPowerLevel;
274 whalCtrl_SetParam(pPowerAutho->hHalCtrl, &ParamInfo);
275
276 return OK;
277 }
278
279
280 /****************************************************************************
281 * MacServices_powerAutho_Endrecovery()
282 ****************************************************************************
283 * DESCRIPTION: initialize module after recovery
284 *
285 * INPUTS: hMacServices - the handle to the MacServices module.
286 *
287 *
288 * OUTPUT: none
289 *
290 * RETURNS: OK or NOK
291 ****************************************************************************/
powerAutho_Restart(TI_HANDLE hMacServices)292 int powerAutho_Restart(TI_HANDLE hMacServices)
293 {
294 powerAutho_t *pPowerAutho = (powerAutho_t*)(((MacServices_t*)hMacServices)->hPowerAutho);
295
296 /* set as 'before init complete' */
297 pPowerAutho->initComplete = FALSE;
298
299 pPowerAutho->m_PowerPolicy = POWERAUTHO_POLICY_AWAKE;
300 pPowerAutho->m_MinPowerLevel = POWERAUTHO_POLICY_AWAKE;
301
302 return pPowerAutho->m_MinPowerLevel;
303 }
304
305
306 /****************************************************************************
307 * MacServices_powerAutho_Endrecovery()
308 ****************************************************************************
309 * DESCRIPTION: updates the PowerPolicy and calcs the new MinPowerPolicy of the sustem
310 *
311 * INPUTS: hMacServices - the handle to the MacServices module.
312 *
313 *
314 * OUTPUT: none
315 *
316 * RETURNS: OK or NOK
317 ****************************************************************************/
MacServices_powerAutho_EndRecovery(TI_HANDLE hMacServices)318 int MacServices_powerAutho_EndRecovery(TI_HANDLE hMacServices)
319 {
320 powerAutho_t *pPowerAutho = (powerAutho_t*)(((MacServices_t*)hMacServices)->hPowerAutho);
321
322 WLAN_REPORT_INFORMATION (pPowerAutho->hReport,ELP_MODULE_LOG,
323 ("MacServices_powerAutho_Endrecovery: PowerPolicy = %d\n",pPowerAutho->m_PowerPolicy));
324
325 return powerAutho_CalcMinPowerLevel(pPowerAutho);
326 }
327
328
329