1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 // Software and any modification/derivatives thereof.
18 // No right, ownership, or interest to MStar Software and any
19 // modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 // supplied together with third party`s software and the use of MStar
23 // Software may require additional licenses from third parties.
24 // Therefore, you hereby agree it is your sole responsibility to separately
25 // obtain any and all third party right and license necessary for your use of
26 // such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 // MStar`s confidential information and you agree to keep MStar`s
30 // confidential information in strictest confidence and not disclose to any
31 // third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 // kind. Any warranties are hereby expressly disclaimed by MStar, including
35 // without limitation, any warranties of merchantability, non-infringement of
36 // intellectual property rights, fitness for a particular purpose, error free
37 // and in conformity with any international standard. You agree to waive any
38 // claim against MStar for any loss, damage, cost or expense that you may
39 // incur related to your use of MStar Software.
40 // In no event shall MStar be liable for any direct, indirect, incidental or
41 // consequential damages, including without limitation, lost of profit or
42 // revenues, lost or damage of data, and unauthorized system use.
43 // You agree that this Section 4 shall still apply without being affected
44 // even if MStar Software has been modified by MStar in accordance with your
45 // request or instruction for your use, except otherwise agreed by both
46 // parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 // services in relation with MStar Software to you for your use of
50 // MStar Software in conjunction with your or your customer`s product
51 // ("Services").
52 // You understand and agree that, except otherwise agreed by both parties in
53 // writing, Services are provided on an "AS IS" basis and the warranty
54 // disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 // or otherwise:
58 // (a) conferring any license or right to use MStar name, trademark, service
59 // mark, symbol or any other identification;
60 // (b) obligating MStar or any of its affiliates to furnish any person,
61 // including without limitation, you and your customers, any assistance
62 // of any kind whatsoever, or any information; or
63 // (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 // of Taiwan, R.O.C., excluding its conflict of law rules.
67 // Any and all dispute arising out hereof or related hereto shall be finally
68 // settled by arbitration referred to the Chinese Arbitration Association,
69 // Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 // Rules of the Association by three (3) arbitrators appointed in accordance
71 // with the said Rules.
72 // The place of arbitration shall be in Taipei, Taiwan and the language shall
73 // be English.
74 // The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2008-2009 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // ("MStar Confidential Information") by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 ////////////////////////////////////////////////////////////////////////////////
94
95 ///////////////////////////////////////////////////////////////////////////////////////////////////
96 ///
97 /// file drvPM.c
98 /// @brief PM Driver Interface
99 /// @author MStar Semiconductor Inc.
100 ///////////////////////////////////////////////////////////////////////////////////////////////////
101
102
103 //-------------------------------------------------------------------------------------------------
104 // Include Files
105 //-------------------------------------------------------------------------------------------------
106 // Internal Definition
107 #define PM_LOCK_SUPPORT 1 // 1: Enable 0: Disable
108
109 // Common Definition
110 #include <string.h> //for memcpy, memset
111 #ifdef MSOS_TYPE_LINUX
112 #include <fcntl.h>
113 #include <sys/ioctl.h>
114 #include "drv_pm_io.h"
115 #endif
116 #include "MsCommon.h"
117 #include "MsVersion.h"
118 #include "drvPM.h"
119
120 #include "halPM.h"
121 #include "regPM.h"
122
123 #include "drvMBX.h"
124 #include "drvMMIO.h"
125 #if PM_LOCK_SUPPORT
126 #include "drvSEM.h"
127 #endif
128
129 #include "ULog.h"
130
131 #define PM_MBX_QUEUESIZE 8
132
133 //-------------------------------------------------------------------------------------------------
134 // Driver Compiler Options
135 //-------------------------------------------------------------------------------------------------
136
137
138 //-------------------------------------------------------------------------------------------------
139 // Local Defines
140 //-------------------------------------------------------------------------------------------------
141 #if PM_LOCK_SUPPORT //-----------------------------------------------------------------------------
142 #define RES_HK51ID 0x01UL
143 #define RES_AeonID 0x02UL
144 #define RES_MipsID 0x03UL
145 #define PMSEMID 0x04UL
146
147 #define TAG_PM "PM"
148
149 #define _PM_ENTRY(u16PMResID) do{ \
150 while (MDrv_SEM_Get_Resource(PMSEMID, u16PMResID) == FALSE); \
151 }while(0)
152
153 #define _PM_RETURN(u16PMResId) do{ \
154 MDrv_SEM_Free_Resource(PMSEMID, u16PMResId); \
155 }while(0)
156 #else //-------------------------------------------------------------------------------------------
157 #define _PM_ENTRY(u16PMResID) do{ }while(0)
158 #define _PM_RETURN(u16PMResId) do{ }while(0)
159 #endif //------------------------------------------------------------------------------------------
160
161 #define PM_MBX_QUEUESIZE 8
162 #define PM_MBX_TIMEOUT 5000
163
164 #ifndef UNUSED
165 #define UNUSED(x) ((x)=(x))
166 #endif
167
168 #define LOWBYTE(u16) ((MS_U8)(u16))
169 #define HIGHBYTE(u16) ((MS_U8)((u16) >> 8))
170
171 #ifdef MSOS_TYPE_NOS
172 extern void mhal_interrupt_lock(void);
173 extern void mhal_interrupt_unlock(void);
174 #endif
175
176 #if defined(__mips__) || defined(__arm__)
177 #define _PA2VA(x) (MS_U32)MsOS_PA2KSEG1((x))
178 #define _VA2PA(x) (MS_U32)MsOS_VA2PA((x))
179
180 #else
181 #define _PA2VA(x) x
182 #define _VA2PA(x) x
183 #endif
184
185 //-------------------------------------------------------------------------------------------------
186 // Local Structurs
187 //-------------------------------------------------------------------------------------------------
188 #ifdef MSOS_TYPE_LINUX
189 static MS_S32 _s32FdPM = -1;
190 #endif
191 //-------------------------------------------------------------------------------------------------
192 // Global Variables
193 //-------------------------------------------------------------------------------------------------
194
195
196 //-------------------------------------------------------------------------------------------------
197 // Local Variables
198 //-------------------------------------------------------------------------------------------------
199 static PM_AckFlags gPmAckFlags;
200 static PM_PWM_AckFlags gPmPWMAckFlags;
201
202 static MSIF_Version _drv_pm_version = {
203 .DDI = { PM_DRV_VERSION },
204 };
205 static PM_DrvInfo _sPmDrvInfo;
206 static PM_DbgLv _gPmDbgLevel = E_PM_DBGLV_ERR_ONLY;
207
208 #define EFUSE_SIZE 8
209 #define MASTER_KEY_SIZE 16
210 #define CHIPID_SIZE 4
211 #define MemAddr_SIZE 4
212
213 //static MS_U8 gPmMasterKey[MASTER_KEY_SIZE];
214 static MS_U8 gPmDeviceID[EFUSE_SIZE];
215 static MS_U8 gPmChipID[CHIPID_SIZE];
216 static MS_U8 gPmMemAddr[MemAddr_SIZE];
217
218 #if PM_LOCK_SUPPORT
219 #ifdef __mips__
220 static MS_U16 _gu16PMResID = RES_MipsID;
221 #else
222 static MS_U16 _gu16PMResID = RES_AeonID;
223 #endif
224 #endif
225
226 static IRRecord_Callback gfIRRecordCallback = NULL;
227
228 //-------------------------------------------------------------------------------------------------
229 // Debug Functions
230 //-------------------------------------------------------------------------------------------------
231 #define PM_DBG_FUNC() if (_gPmDbgLevel >= E_PM_DBGLV_ALL) \
232 {MS_DEBUG_MSG(ULOGD(TAG_PM, "\t==== %s ====\n", __FUNCTION__));}
233 #define PM_DBG_INFO(x, args...) if (_gPmDbgLevel >= E_PM_DBGLV_INFO ) \
234 {MS_DEBUG_MSG(ULOGI(TAG_PM, x, ##args));}
235 #define PM_DBG_ERR(x, args...) if (_gPmDbgLevel >= E_PM_DBGLV_ERR_ONLY) \
236 {MS_DEBUG_MSG(ULOGE(TAG_PM, x, ##args));}
237 #define PM_DBG_STR(x) //(x)
238
239 //-------------------------------------------------------------------------------------------------
240 // Local Functions
241 //-------------------------------------------------------------------------------------------------
242
243 //-------------------------------------------------------------------------------------------------
244 /// PM MailBox Handler
245 /// @param pData \b IN: mailbox data configuration
246 /// @return @ref MBX_Result
247 //-------------------------------------------------------------------------------------------------
_MDrv_PM_MailBoxHandler(void * pData)248 MBX_Result _MDrv_PM_MailBoxHandler(void *pData)
249 {
250 MBX_Msg MB_Command;
251
252 MBX_Result mbxResult = E_MBX_UNKNOW_ERROR;
253
254 PM_DBG_FUNC();
255
256 mbxResult = MDrv_MBX_RecvMsg(E_MBX_CLASS_PM_WAIT, &MB_Command, PM_MBX_TIMEOUT/*ms*/, MBX_CHECK_NORMAL_MSG);
257 if (E_MBX_ERR_TIME_OUT == mbxResult)
258 {
259 return mbxResult;
260 }
261
262 if (E_MBX_SUCCESS == mbxResult)
263 {
264 if ((MB_Command.u8Ctrl == 0) || (MB_Command.u8Ctrl == 1))
265 {
266 PM_DBG_INFO("Get PM command: 0x%02x.\n", MB_Command.u8Index);
267 switch (MB_Command.u8Index)
268 {
269 case PM_CMDIDX_ACK_51ToAEON:
270 switch(MB_Command.u8Parameters[0])
271 {
272 case PM_CMDIDX_INIT:
273 *((PM_Result*)pData) = (PM_Result)MB_Command.u8Parameters[1];
274 gPmAckFlags &= (PM_AckFlags)(~E_PM_ACKFLG_WAIT_INIT);
275 break;
276 case PM_CMDIDX_GET_STATUS:
277 *((PM_DrvStatus*)pData) = (PM_DrvStatus)MB_Command.u8Parameters[1];
278 gPmAckFlags &= (PM_AckFlags)(~E_PM_ACKFLG_WAIT_STATUS);
279 break;
280 case PM_CMDIDX_GET_LIBVER:
281 *((PM_Result*)pData) = (PM_Result)MB_Command.u8Parameters[1];
282 gPmAckFlags &= (PM_AckFlags)(~E_PM_ACKFLG_WAIT_LIBVER);
283 break;
284 case PM_CMDIDX_POWER_DOWN:
285 *((PM_Result*)pData) = (PM_Result)MB_Command.u8Parameters[1];
286 gPmAckFlags &= (PM_AckFlags)(~E_PM_ACKFLG_WAIT_POWERDOWN);
287 break;
288 case PM_CMDIDX_RTC_INIT:
289 *((PM_Result*)pData) = (PM_Result)MB_Command.u8Parameters[1];
290 gPmAckFlags &= (PM_AckFlags)(~E_PM_ACKFLG_WAIT_RTCINIT);
291 break;
292 case PM_CMDIDX_RTC_SETCOUNTER:
293 *((PM_Result*)pData) = (PM_Result)MB_Command.u8Parameters[1];
294 gPmAckFlags &= (PM_AckFlags)(~E_PM_ACKFLG_WAIT_RTCSETCOUNTER);
295 break;
296 case PM_CMDIDX_RTC_GETCOUNTER:
297 *((PM_Result*)pData) = (PM_Result)MB_Command.u8Parameters[1];
298 gPmAckFlags &= (PM_AckFlags)(~E_PM_ACKFLG_WAIT_RTCGETCOUNTER);
299 break;
300 case PM_CMDIDX_RTC_SETMATCHCOUNTER:
301 *((PM_Result*)pData) = (PM_Result)MB_Command.u8Parameters[1];
302 gPmAckFlags &= (PM_AckFlags)(~E_PM_ACKFLG_WAIT_RTCSETMATCHCOUNTER);
303 break;
304 case PM_CMDIDX_RTC_GETMATCHCOUNTER:
305 *((PM_Result*)pData) = (PM_Result)MB_Command.u8Parameters[1];
306 gPmAckFlags &= (PM_AckFlags)(~E_PM_ACKFLG_WAIT_RTCGETMATCHCOUNTER);
307 break;
308 case PM_CMDIDX_GET_INFO:
309 *((PM_Result*)pData) = (PM_Result)MB_Command.u8Parameters[1];
310 gPmAckFlags &= (PM_AckFlags)(~E_PM_ACKFLG_WAIT_INFO);
311 break;
312 case PM_CMDIDX_GET_MASTERKEY:
313 *((PM_Result*)pData) = (PM_Result)MB_Command.u8Parameters[1];
314 gPmAckFlags &= (PM_AckFlags)(~E_PM_ACKFLG_WAIT_GETMASTERKEY);
315 break;
316 case PM_CMDIDX_GET_DEVICEID:
317 *((PM_Result*)pData) = (PM_Result)MB_Command.u8Parameters[1];
318 gPmAckFlags &= (PM_AckFlags)(~E_PM_ACKFLG_WAIT_GETDEVICEID);
319 gPmDeviceID[0] = MB_Command.u8Parameters[2];
320 gPmDeviceID[1] = MB_Command.u8Parameters[3];
321 gPmDeviceID[2] = MB_Command.u8Parameters[4];
322 gPmDeviceID[3] = MB_Command.u8Parameters[5];
323 gPmDeviceID[4] = MB_Command.u8Parameters[6];
324 gPmDeviceID[5] = MB_Command.u8Parameters[7];
325 break;
326 case PM_CMDIDX_GET_CHIPID:
327 *((PM_Result*)pData) = (PM_Result)MB_Command.u8Parameters[1];
328 gPmAckFlags &= (PM_AckFlags)(~E_PM_ACKFLG_WAIT_GETCHIPID);
329 gPmChipID[0] = MB_Command.u8Parameters[2];
330 gPmChipID[1] = MB_Command.u8Parameters[3];
331 gPmChipID[2] = MB_Command.u8Parameters[4];
332 gPmChipID[3] = MB_Command.u8Parameters[5];
333 break;
334 case PM_CMDIDX_GPIO_INIT:
335 *((PM_Result*)pData) = (PM_Result)MB_Command.u8Parameters[1];
336 gPmAckFlags &= (PM_AckFlags)(~E_PM_ACKFLG_WAIT_GPIOINIT);
337 break;
338 case PM_CMDIDX_GET_PM_MEMADDR:
339 *((PM_Result*)pData) = (PM_Result)MB_Command.u8Parameters[1];
340 gPmAckFlags &= (PM_AckFlags)(~E_PM_ACKFLG_WAIT_GETPMMEMADDR);
341 gPmMemAddr[0] = MB_Command.u8Parameters[2];
342 gPmMemAddr[1] = MB_Command.u8Parameters[3];
343 gPmMemAddr[2] = MB_Command.u8Parameters[4];
344 gPmMemAddr[3] = MB_Command.u8Parameters[5];
345 break;
346 case PM_CMDIDX_GETEXTRASRAMDATA:
347 *((PM_Result*)pData) = (PM_Result)MB_Command.u8Parameters[1];
348 gPmAckFlags &= (PM_AckFlags)(~E_PM_ACKFLG_WAIT_GETEXTRASRAMDATA);
349 break;
350 case PM_CMDIDX_SETEXTRASRAMDATA:
351 *((PM_Result*)pData) = (PM_Result)MB_Command.u8Parameters[1];
352 gPmAckFlags &= (PM_AckFlags)(~E_PM_ACKFLG_WAIT_SETEXTRASRAMDATA);
353 break;
354 default:
355 break;
356 }
357 break;
358
359 default:
360 break;
361 }
362 }
363 }
364
365 return mbxResult;
366 }
367
_MDrv_PM_DummyMiuFifo(void)368 void _MDrv_PM_DummyMiuFifo(void)
369 {
370 static PM_Dummy PmDummy;
371 MS_U8 index;
372
373 for(index = 0; index<16; index++)
374 {
375 PmDummy.u8Reserved[index] = index;
376 //Coverity Fixed
377 if( PmDummy.u8Reserved[index] != index )
378 {
379 PmDummy.u8Reserved[index] = index;
380 }
381 }
382 }
383
384 //-------------------------------------------------------------------------------------------------
385 // Global Functions
386 //-------------------------------------------------------------------------------------------------
387 //-------------------------------------------------------------------------------------------------
388 /// Check if runtime_pm is running
389 /// @return TRUE : Running
390 /// @return FALSE : Not running
391 //-------------------------------------------------------------------------------------------------
MDrv_PM_isRunning(void)392 MS_BOOL MDrv_PM_isRunning(void)
393 {
394 MS_BOOL bRet;
395 //PM_DBG_ERR("MDrv_PM_isRunning is not support\n");
396 bRet = HAL_PM_isRunning();
397 return bRet;
398 }
399
400 //-------------------------------------------------------------------------------------------------
401 /// attach interrupt request
402 //-------------------------------------------------------------------------------------------------
MDrv_PM_InterruptRequest(void)403 void MDrv_PM_InterruptRequest( void )
404 {
405 PM_DBG_ERR("MDrv_PM_InterruptRequest is not support\n");
406 }
407
408 //-------------------------------------------------------------------------------------------------
409 /// Load firmware data
410 /// @param pPmCode \b IN: PM code data
411 /// @param u16Len \b IN: Size of PM code data
412 //-------------------------------------------------------------------------------------------------
MDrv_PM_LoadFw(MS_U8 * pPmCode,MS_U16 u16Len)413 void MDrv_PM_LoadFw( MS_U8 *pPmCode, MS_U16 u16Len )
414 {
415 PM_DBG_ERR("MDrv_PM_LoadFw is not support\n");
416 }
417
418 //-------------------------------------------------------------------------------------------------
419 /// Write 1 byte data to M4 Lite register
420 /// @param u16Addr \b IN: register address
421 /// @param u8Data \b IN: 1 byte value to write
422 /// @return TRUE : succeed
423 /// @return FALSE : fail
424 //-------------------------------------------------------------------------------------------------
MDrv_PM_RegWrite(MS_U16 u16Addr,MS_U8 u8Data)425 MS_BOOL MDrv_PM_RegWrite( MS_U16 u16Addr, MS_U8 u8Data )
426 {
427 PM_DBG_ERR("MDrv_PM_RegWrite is not support\n");
428 return FALSE;
429 }
430
431 //-------------------------------------------------------------------------------------------------
432 /// Read 1 byte data from M4 Lite register
433 /// @param u16Addr \b IN: register address
434 /// @return unsinged char value: 1 byte value for read
435 //-------------------------------------------------------------------------------------------------
MDrv_PM_RegRead(MS_U16 u16Addr)436 MS_U8 MDrv_PM_RegRead( MS_U16 u16Addr )
437 {
438 PM_DBG_ERR("MDrv_PM_RegRead is not support\n");
439 return FALSE;
440 }
441
442 //-------------------------------------------------------------------------------------------------
443 /// set 1 bit data to M4 Lite register
444 /// @param u16Addr \b IN: register address
445 /// @param bBit \b IN: bit value to set
446 /// @param u8BitPos \b IN: which bit to set
447 //-------------------------------------------------------------------------------------------------
MDrv_PM_RegWriteBit(MS_U16 u16Addr,MS_U8 bBit,MS_U8 u8BitPos)448 void MDrv_PM_RegWriteBit(MS_U16 u16Addr, MS_U8 bBit, MS_U8 u8BitPos )
449 {
450 PM_DBG_ERR("MDrv_PM_RegWriteBit is not support\n");
451 }
452
453 //-------------------------------------------------------------------------------------------------
454 /// get 1 bit data from M4 Lite register
455 /// @param u16Addr \b IN: register address
456 /// @param u8BitPos \b IN: which bit to read
457 /// @return unsinged char value: 8 bits (1 byte) value for read with bit mask
458 //-------------------------------------------------------------------------------------------------
MDrv_PM_RegReadBit(MS_U16 u16Addr,MS_U8 u8BitPos)459 MS_U8 MDrv_PM_RegReadBit(MS_U16 u16Addr, MS_U8 u8BitPos)
460 {
461 PM_DBG_ERR("MDrv_PM_RegReadBit is not support\n");
462 return FALSE;
463 }
464
465 //-------------------------------------------------------------------------------------------------
466 /// Write 2 byte data to M4 Lite register
467 /// @param u16RegIndex \b IN: register address
468 /// @param u16Value \b IN: 2 byte value to write
469 //-------------------------------------------------------------------------------------------------
MDrv_PM_RegWrite2byte(MS_U16 u16RegIndex,MS_U16 u16Value)470 void MDrv_PM_RegWrite2byte( MS_U16 u16RegIndex, MS_U16 u16Value )
471 {
472 PM_DBG_ERR("MDrv_PM_RegWrite2byte is not support\n");
473 }
474
475 //-------------------------------------------------------------------------------------------------
476 /// Write 3 byte data to M4 Lite register
477 /// @param u16Regndex \b IN: register address
478 /// @param u32Value \b IN: 4 byte value to write
479 //-------------------------------------------------------------------------------------------------
MDrv_PM_RegWrite3byte(MS_U16 u16Regndex,MS_U32 u32Value)480 void MDrv_PM_RegWrite3byte( MS_U16 u16Regndex, MS_U32 u32Value )
481 {
482 PM_DBG_ERR("MDrv_PM_RegWrite3byte is not support\n");
483 }
484
485 //-------------------------------------------------------------------------------------------------
486 /// PM Sleep Control Function
487 /// @param u8opcode \b IN: control command
488 /// @param u8Data \b IN: 8 bits data
489 /// @param u16Data \b IN: 16 bits data
490 /// @return TRUE : succeed
491 /// @return FALSE : fail
492 //-------------------------------------------------------------------------------------------------
MDrv_PM_Control(MS_U8 u8opcode,MS_U8 u8Data,MS_U16 u16Data)493 MS_BOOL MDrv_PM_Control( MS_U8 u8opcode, MS_U8 u8Data, MS_U16 u16Data )
494 {
495 PM_DBG_ERR("MDrv_PM_Control is not support\n");
496 return FALSE;
497 }
498
499 //-------------------------------------------------------------------------------------------------
500 /// PM Control Write Function
501 /// @param u8Opcode \b IN: control command
502 /// @param u8CmdType \b IN: 8 bits data
503 /// @param u8DataNum \b IN: 8 bits data
504 /// @param pu8Data \b IN: 8 bits data
505 /// @return TRUE : succeed
506 /// @return FALSE : fail
507 //-------------------------------------------------------------------------------------------------
MDrv_PM_CtrlWrite(MS_U8 u8Opcode,MS_U8 u8CmdType,MS_U8 u8DataNum,MS_U8 * pu8Data)508 MS_BOOL MDrv_PM_CtrlWrite( MS_U8 u8Opcode, MS_U8 u8CmdType, MS_U8 u8DataNum, MS_U8 *pu8Data )
509 {
510 PM_DBG_ERR("MDrv_PM_CtrlWrite is not support\n");
511 return FALSE;
512 }
513
514
515 //-------------------------------------------------------------------------------------------------
516 /// PM Control Read Function
517 /// @param u8Opcode \b IN: control command
518 /// @param u8CmdType \b IN: 8 bits data
519 /// @param u8DataNum \b IN: 8 bits data
520 /// @param pu8Data \b IN: 8 bits data
521 /// @return TRUE : succeed
522 /// @return FALSE : fail
523 //-------------------------------------------------------------------------------------------------
MDrv_PM_CtrlRead(MS_U8 u8Opcode,MS_U8 u8CmdType,MS_U8 u8DataNum,MS_U8 * pu8Data)524 MS_BOOL MDrv_PM_CtrlRead( MS_U8 u8Opcode, MS_U8 u8CmdType, MS_U8 u8DataNum, MS_U8 *pu8Data )
525 {
526 PM_DBG_ERR("MDrv_PM_CtrlRead is not support\n");
527 return FALSE;
528 }
529
530 //-------------------------------------------------------------------------------------------------
531 /// Write array data to memory of MICOM Module
532 /// @param pu8Data \b IN: Data write to PM
533 /// @param u16MemLen \b IN: length of data BYTE write to PM Memory
534 /// @return TRUE : succeed
535 /// @return FALSE : fail
536 //-------------------------------------------------------------------------------------------------
MDrv_PM_MemoryWrite(MS_U8 * pu8Data,MS_U16 u16MemLen)537 MS_BOOL MDrv_PM_MemoryWrite(MS_U8 *pu8Data, MS_U16 u16MemLen)
538 {
539 PM_DBG_ERR("MDrv_PM_MemoryWrite is not support\n");
540 return FALSE;
541 }
542
543 //-------------------------------------------------------------------------------------------------
544 /// Read array data from memory of MICOM Module
545 /// @param pu8Data \b IN: Data write to PM
546 /// @param u16MemLen \b IN: length of data BYTE read from PM Memory
547 /// @return TRUE : succeed
548 /// @return FALSE : fail
549 //-------------------------------------------------------------------------------------------------
MDrv_PM_MemoryRead(MS_U8 * pu8Data,MS_U16 u16MemLen)550 MS_BOOL MDrv_PM_MemoryRead(MS_U8 *pu8Data, MS_U16 u16MemLen)
551 {
552 PM_DBG_ERR("MDrv_PM_MemoryRead is not support\n");
553 return FALSE;
554 }
555
556 //-------------------------------------------------------------------------------------------------
557 /// Enable RTC interrupt
558 /// @param bEnable \b IN: TRUE for enable, FALSE for disable
559 //-------------------------------------------------------------------------------------------------
MDrv_PM_RTCEnableInterrupt(MS_BOOL bEnable)560 void MDrv_PM_RTCEnableInterrupt(MS_BOOL bEnable)
561 {
562 _PM_ENTRY(_gu16PMResID);
563 HAL_PM_WriteRegBit(REG_PMRTC_CTRL, bEnable? 0:1, PMRTC_CTRL_INT_MASK);
564 HAL_PM_WriteRegBit(REG_PMRTC_CTRL, bEnable? 0:1, PMRTC_CTRL_INT_CLEAR);
565 _PM_RETURN(_gu16PMResID);
566 //PM_DBG_ERR("MDrv_PM_RTCEnableInterrupt is not support\n");
567 }
568
569 //-------------------------------------------------------------------------------------------------
570 /// Set rtc match time
571 /// @param u32PmSysTime \b IN: RTC match time
572 //-------------------------------------------------------------------------------------------------
MDrv_PM_RTCSetMatchTime(MS_U32 u32PmSysTime)573 void MDrv_PM_RTCSetMatchTime(MS_U32 u32PmSysTime)
574 {
575 _MDrv_PM_DummyMiuFifo();
576 _PM_ENTRY(_gu16PMResID);
577 HAL_PM_RtcSetMatchCounter(0, u32PmSysTime);
578 _PM_RETURN(_gu16PMResID);
579 //PM_DBG_ERR("MDrv_PM_RTCSetMatchTime is not support\n");
580 }
581
582
583 /*add by owen.qin begin*/
MDrv_PM_RTC2EnableInterrupt(MS_BOOL bEnable)584 void MDrv_PM_RTC2EnableInterrupt(MS_BOOL bEnable)
585 {
586
587 _PM_ENTRY(_gu16PMResID);
588 HAL_PM_WriteRegBit(REG_PMRTC1_CTRL, bEnable? 0:1, PMRTC_CTRL_INT_MASK);
589 HAL_PM_WriteRegBit(REG_PMRTC1_CTRL, bEnable? 0:1, PMRTC_CTRL_INT_CLEAR);
590 _PM_RETURN(_gu16PMResID);
591
592 }
593
MDrv_PM_RTC2SetMatchTime(MS_U32 u32PmSysTime)594 void MDrv_PM_RTC2SetMatchTime(MS_U32 u32PmSysTime)
595 {
596
597 _MDrv_PM_DummyMiuFifo();
598 _PM_ENTRY(_gu16PMResID);
599 HAL_PM_RtcSetMatchCounter(1, u32PmSysTime);
600 _PM_RETURN(_gu16PMResID);
601
602 }
603 /*add by owen.qin end*/
604
605 //-------------------------------------------------------------------------------------------------
606 /// Get rtc match time
607 /// @return unsinged long value: RTC match time
608 //-------------------------------------------------------------------------------------------------
MDrv_PM_RTCGetMatchTime(void)609 MS_U32 MDrv_PM_RTCGetMatchTime(void)
610 {
611
612 MS_U32 pu32PmSysTime;
613
614 _MDrv_PM_DummyMiuFifo();
615 _PM_ENTRY(_gu16PMResID);
616 pu32PmSysTime = HAL_PM_RtcGetMatchCounter(0);
617 _PM_RETURN(_gu16PMResID);
618 //PM_DBG_ERR("MDrv_PM_RTCGetMatchTime is not support\n");
619 return pu32PmSysTime;
620 }
621
622 //-------------------------------------------------------------------------------------------------
623 /// Set rtc system time
624 /// @param u32PmSysTime \b IN: RTC system time
625 //-------------------------------------------------------------------------------------------------
MDrv_PM_RTCSetSystemTime(MS_U32 u32PmSysTime)626 void MDrv_PM_RTCSetSystemTime(MS_U32 u32PmSysTime)
627 {
628 _MDrv_PM_DummyMiuFifo();
629 _PM_ENTRY(_gu16PMResID);
630 HAL_PM_RtcSetCounter(0, u32PmSysTime);
631 _PM_RETURN(_gu16PMResID);
632 //PM_DBG_ERR("MDrv_PM_RTCSetSystemTime is not support\n");
633 }
634
635 //-------------------------------------------------------------------------------------------------
636 /// Get rtc system time
637 /// @return unsinged long value: RTC system time
638 //-------------------------------------------------------------------------------------------------
MDrv_PM_RTCGetSystemTime(void)639 MS_U32 MDrv_PM_RTCGetSystemTime(void)
640 {
641 _MDrv_PM_DummyMiuFifo();
642 MS_U32 pu32PmSysTime;
643 _PM_ENTRY(_gu16PMResID);
644 pu32PmSysTime = HAL_PM_RtcGetCounter(0);
645 _PM_RETURN(_gu16PMResID);
646 //PM_DBG_ERR("MDrv_PM_RTCGetSystemTime is not support\n");
647 return pu32PmSysTime;
648 }
649
650 //-------------------------------------------------------------------------------------------------
651 /// RTC initialize
652 /// @param u32CtrlWord \b IN: Crystal clock frequency
653 //-------------------------------------------------------------------------------------------------
MDrv_PM_RTCInit(MS_U32 u32CtrlWord)654 void MDrv_PM_RTCInit(MS_U32 u32CtrlWord)
655 {
656 PM_DBG_ERR("MDrv_PM_RTCInit is not support\n");
657 }
658
659 //-------------------------------------------------------------------------------------------------
660 /// IR initialize
661 /// @param irclk_mhz \b IN: Crystal clock frequency
662 /// @param irRegCfg \b IN: IR register configuration
663 //-------------------------------------------------------------------------------------------------
MDrv_PM_IRInit(MS_U8 irclk_mhz,PM_IrRegCfg * irRegCfg)664 void MDrv_PM_IRInit(MS_U8 irclk_mhz, PM_IrRegCfg *irRegCfg)
665 {
666 PM_DBG_ERR("MDrv_PM_IRInit is not support\n");
667 }
668
669 //-------------------------------------------------------------------------------------------------
670 /// Keypad initialize
671 /// @param sarRegCfg \b IN: SAR register configuration
672 /// @param sarParamCfg \b IN: SAR data configuration
673 //-------------------------------------------------------------------------------------------------
MDrv_PM_KeypadInit(PM_SarRegCfg * sarRegCfg,PM_SarParamCfg * sarParamCfg)674 void MDrv_PM_KeypadInit(PM_SarRegCfg *sarRegCfg, PM_SarParamCfg *sarParamCfg)
675 {
676 PM_DBG_ERR("MDrv_PM_KeypadInit is not support\n");
677 }
678
679 //-------------------------------------------------------------------------------------------------
680 /// Adjust internal clock
681 //-------------------------------------------------------------------------------------------------
MDrv_PM_CalibrateRC(void)682 void MDrv_PM_CalibrateRC(void)
683 {
684 PM_DBG_ERR("MDrv_PM_CalibrateRC is not support\n");
685 }
686
687 //-------------------------------------------------------------------------------------------------
688 /// Check if pmsleep firmware is downloaded
689 /// @return TRUE : succeed
690 /// @return FALSE : fail
691 //-------------------------------------------------------------------------------------------------
MDrv_PM_isDownloaded(void)692 MS_BOOL MDrv_PM_isDownloaded(void)
693 {
694 PM_DBG_ERR("MDrv_PM_isDownloaded is not support\n");
695 return FALSE;
696 }
697
698 //-------------------------------------------------------------------------------------------------
699 /// Set pmsleep firmware is downloaded
700 //-------------------------------------------------------------------------------------------------
MDrv_PM_Set_Download(void)701 void MDrv_PM_Set_Download(void)
702 {
703 PM_DBG_ERR("MDrv_PM_Set_Download is not support\n");
704 }
705
706 //-------------------------------------------------------------------------------------------------
707 /// Attach different IRQ services
708 /// @param irq \b IN: IRQ type
709 /// @param isr \b IN: pointer of service funciton
710 /// @param data \b IN: interrupt/exception data
711 //-------------------------------------------------------------------------------------------------
MDrv_PM_IrqAttach(PM_IRQ_TYPE irq,PM_IsrCb_Type isr,MS_U32 data)712 void MDrv_PM_IrqAttach(PM_IRQ_TYPE irq, PM_IsrCb_Type isr, MS_U32 data)
713 {
714 PM_DBG_ERR("MDrv_PM_IrqAttach is not support\n");
715 }
716
717 //-------------------------------------------------------------------------------------------------
718 /// Detach specific IRQ services
719 /// @param irq \b IN: IRQ type
720 //-------------------------------------------------------------------------------------------------
MDrv_PM_IrqDetach(PM_IRQ_TYPE irq)721 void MDrv_PM_IrqDetach(PM_IRQ_TYPE irq)
722 {
723 PM_DBG_ERR("MDrv_PM_IrqDetach is not support\n");
724 }
725
726 //-------------------------------------------------------------------------------------------------
727 /// Enable specific irq request
728 /// @param irq \b IN: IRQ type
729 //-------------------------------------------------------------------------------------------------
MDrv_PM_IrqUnmask(PM_IRQ_TYPE irq)730 void MDrv_PM_IrqUnmask(PM_IRQ_TYPE irq)
731 {
732 PM_DBG_ERR("MDrv_PM_IrqUnmask is not support\n");
733 }
734
735 //-------------------------------------------------------------------------------------------------
736 /// Disable specific irq request
737 /// @param irq \b IN: IRQ type
738 //-------------------------------------------------------------------------------------------------
MDrv_PM_IrqMask(PM_IRQ_TYPE irq)739 void MDrv_PM_IrqMask(PM_IRQ_TYPE irq)
740 {
741 PM_DBG_ERR("MDrv_PM_IrqMask is not support\n");
742 }
743
744 //-------------------------------------------------------------------------------------------------
745 /// Disable all PM irq requests
746 //-------------------------------------------------------------------------------------------------
MDrv_PM_IrqMaskAll(void)747 void MDrv_PM_IrqMaskAll(void)
748 {
749 PM_DBG_ERR("MDrv_PM_IrqMask is not support\n");
750 }
751
752 //-------------------------------------------------------------------------------------------------
753 /// PM driver initialize
754 /// @param pPmWakeCfg \b IN: PM wake-up configuration
755 /// @return @ref PM_Result
756 //-------------------------------------------------------------------------------------------------
MDrv_PM_Init(PM_WakeCfg * pPmWakeCfg)757 PM_Result MDrv_PM_Init(PM_WakeCfg *pPmWakeCfg)
758 {
759 MS_VIRT virtSrcAddr;
760 PM_Result PmResult = E_PM_FAIL;
761 MBX_Result mbxResult = E_MBX_UNKNOW_ERROR;
762 MBX_Msg MB_Command;
763
764 MS_U32 MBX_Resendcnt = 0;
765 MS_U16 u16WakeSrc = 0;
766
767 _MDrv_PM_DummyMiuFifo();
768
769 PM_DBG_FUNC();
770
771 memset((void*)&MB_Command, 0, sizeof(MBX_Msg));
772
773 gPmAckFlags |= E_PM_ACKFLG_WAIT_INIT;
774
775 virtSrcAddr = (MS_VIRT)pPmWakeCfg;
776 PM_WakeCfg *PmWakeCfg = (PM_WakeCfg*)_PA2VA((MS_VIRT)pPmWakeCfg);
777
778 if(PmWakeCfg->bPmWakeEnableIR == 1) u16WakeSrc |= (1<<0);
779 if(PmWakeCfg->bPmWakeEnableSAR == 1) u16WakeSrc |= (1<<1);
780 if(PmWakeCfg->bPmWakeEnableGPIO0 == 1) u16WakeSrc |= (1<<2);
781 if(PmWakeCfg->bPmWakeEnableGPIO1 == 1) u16WakeSrc |= (1<<3);
782 if(PmWakeCfg->bPmWakeEnableUART1 == 1) u16WakeSrc |= (1<<4);
783 if(PmWakeCfg->bPmWakeEnableSYNC == 1) u16WakeSrc |= (1<<5);
784 if(PmWakeCfg->bPmWakeEnableESYNC == 1) u16WakeSrc |= (1<<6);
785 if(PmWakeCfg->bPmWakeEnableRTC0 == 1) u16WakeSrc |= (1<<7);
786 if(PmWakeCfg->bPmWakeEnableRTC1 == 1) u16WakeSrc |= (1<<8);
787 if(PmWakeCfg->bPmWakeEnableDVI0 == 1) u16WakeSrc |= (1<<9);
788 if(PmWakeCfg->bPmWakeEnableDVI2 == 1) u16WakeSrc |= (1<<10);
789 if(PmWakeCfg->bPmWakeEnableCEC == 1) u16WakeSrc |= (1<<11);
790 if(PmWakeCfg->bPmWakeEnableAVLINK == 1) u16WakeSrc |= (1<<12);
791 if(PmWakeCfg->bPmWakeEnableMHL == 1) u16WakeSrc |= (1<<13);
792 if(PmWakeCfg->bPmWakeEnableWOL == 1) u16WakeSrc |= (1<<14);
793
794 HAL_PM_SetWakupDevice(u16WakeSrc);
795
796 // send to PM51
797 {
798 MB_Command.eRoleID = E_MBX_ROLE_PM;
799 MB_Command.eMsgType = E_MBX_MSG_TYPE_INSTANT;
800 MB_Command.u8Ctrl = 0; //0x01;
801 MB_Command.u8MsgClass = E_MBX_CLASS_PM_NOWAIT;
802 MB_Command.u8Index = PM_CMDIDX_INIT;
803 MB_Command.u8ParameterCount = 4;
804 MB_Command.u8Parameters[0] = (MS_U8)(virtSrcAddr>>24);
805 MB_Command.u8Parameters[1] = (MS_U8)(virtSrcAddr>>16);
806 MB_Command.u8Parameters[2] = (MS_U8)(virtSrcAddr>>8);
807 MB_Command.u8Parameters[3] = (MS_U8)(virtSrcAddr&0x000000FFUL);
808
809 while(E_MBX_SUCCESS != (mbxResult = MDrv_MBX_SendMsg(&MB_Command)))
810 {
811 //Error Handling here:
812 }
813 }
814
815 // Waiting for PM51 Power Management initialization done
816 do
817 {
818 if(MBX_Resendcnt<10)
819 {
820 mbxResult = _MDrv_PM_MailBoxHandler(&PmResult);
821 MBX_Resendcnt++;
822 }
823 else
824 {
825 MBX_Resendcnt=0;
826 while(E_MBX_SUCCESS != (mbxResult = MDrv_MBX_SendMsg(&MB_Command)))
827 {
828 //Error Handling here:
829 }
830 }
831 }
832 while((gPmAckFlags & E_PM_ACKFLG_WAIT_INIT) &&
833 (mbxResult != E_MBX_ERR_TIME_OUT));
834
835 if( E_MBX_SUCCESS != mbxResult)
836 {
837 PmResult = E_PM_FAIL;
838 PM_DBG_ERR("MDrv_PM_Init Fail\n");
839 }
840 else
841 {
842 PmResult = E_PM_OK;
843 PM_DBG_INFO("MDrv_PM_Init OK\n");
844 }
845
846 return PmResult;
847 }
848
849 //-------------------------------------------------------------------------------------------------
850 /// PM driver get status
851 /// @param pDrvStatus \b IN: PM driver status configuration
852 /// @return @ref PM_Result
853 //-------------------------------------------------------------------------------------------------
MDrv_PM_GetStatus(PM_DrvStatus * pDrvStatus)854 PM_Result MDrv_PM_GetStatus(PM_DrvStatus *pDrvStatus)
855 {
856 PM_Result PmResult = E_PM_FAIL;
857
858 _MDrv_PM_DummyMiuFifo();
859
860 return PmResult;
861
862 }
863
864 //-------------------------------------------------------------------------------------------------
865 /// PM driver get library version
866 /// @param pPmLibVer \b IN: PM driver library version configuration
867 /// @return @ref PM_Result
868 //-------------------------------------------------------------------------------------------------
MDrv_PM_GetLibVer(const MSIF_Version ** ppVersion)869 PM_Result MDrv_PM_GetLibVer(const MSIF_Version **ppVersion)
870 {
871 PM_Result PmResult = E_PM_FAIL;
872
873 if (!ppVersion)
874 return E_PM_FAIL;
875
876 *ppVersion = &_drv_pm_version;
877 PmResult = E_PM_OK;
878
879 return PmResult;
880 }
881
882 //-------------------------------------------------------------------------------------------------
883 /// PM driver power down
884 /// @param pPmPowerDownCfg \b IN: PM driver power down configuration
885 /// @return @ref PM_Result
886 //-------------------------------------------------------------------------------------------------
MDrv_PM_PowerDown(PM_PowerDownCfg * pPmPowerDownCfg)887 PM_Result MDrv_PM_PowerDown(PM_PowerDownCfg *pPmPowerDownCfg)
888 {
889 MS_VIRT virtSrcAddr;
890 PM_Result PmResult = E_PM_FAIL;
891
892 _MDrv_PM_DummyMiuFifo();
893
894 MBX_Result mbxResult = E_MBX_UNKNOW_ERROR;
895 MBX_Msg MB_Command;
896
897 MS_U32 MBX_Resendcnt = 0;
898
899 PM_DBG_FUNC();
900
901 memset((void*)&MB_Command, 0, sizeof(MBX_Msg));
902
903 gPmAckFlags |= E_PM_ACKFLG_WAIT_POWERDOWN;
904
905 virtSrcAddr = (MS_VIRT)pPmPowerDownCfg;
906
907 // send to PM51
908 {
909 MB_Command.eRoleID = E_MBX_ROLE_PM;
910 MB_Command.eMsgType = E_MBX_MSG_TYPE_INSTANT;
911 MB_Command.u8Ctrl = 0; //0x01;
912 MB_Command.u8MsgClass = E_MBX_CLASS_PM_NOWAIT;
913 MB_Command.u8Index = PM_CMDIDX_POWER_DOWN;
914 MB_Command.u8ParameterCount = 4;
915 MB_Command.u8Parameters[0] = (MS_U8)(virtSrcAddr>>24);
916 MB_Command.u8Parameters[1] = (MS_U8)(virtSrcAddr>>16);
917 MB_Command.u8Parameters[2] = (MS_U8)(virtSrcAddr>>8);
918 MB_Command.u8Parameters[3] = (MS_U8)(virtSrcAddr&0x000000FFUL);
919
920 while(E_MBX_SUCCESS != (mbxResult = MDrv_MBX_SendMsg(&MB_Command)))
921 {
922 //Error Handling here:
923 }
924 }
925
926 do
927 {
928 if(MBX_Resendcnt<10)
929 {
930 mbxResult = _MDrv_PM_MailBoxHandler(&PmResult);
931 MBX_Resendcnt++;
932 }
933 else
934 {
935 MBX_Resendcnt=0;
936 while(E_MBX_SUCCESS != (mbxResult = MDrv_MBX_SendMsg(&MB_Command)))
937 {
938 //Error Handling here:
939 }
940 }
941 }
942 while((gPmAckFlags & E_PM_ACKFLG_WAIT_POWERDOWN) &&
943 (mbxResult != E_MBX_ERR_TIME_OUT));
944
945 if( E_MBX_SUCCESS != mbxResult)
946 {
947 PmResult = E_PM_FAIL;
948 PM_DBG_ERR("MDrv_PM_PowerDown Fail\n");
949 }
950 else
951 {
952 PmResult = E_PM_OK;
953 PM_DBG_INFO("MDrv_PM_PowerDown OK\n");
954 }
955
956
957 return PmResult;
958 }
959
MDrv_PM_GetMasterKey(MS_U8 * pPmPowerDownCfg)960 PM_Result MDrv_PM_GetMasterKey(MS_U8 *pPmPowerDownCfg)
961 {
962 MS_VIRT virtSrcAddr;
963 PM_Result PmResult = E_PM_FAIL;
964
965 _MDrv_PM_DummyMiuFifo();
966
967 MBX_Result mbxResult = E_MBX_UNKNOW_ERROR;
968 MBX_Msg MB_Command;
969
970 MS_U32 MBX_Resendcnt = 0;
971
972 PM_DBG_FUNC();
973
974 memset((void*)&MB_Command, 0, sizeof(MBX_Msg));
975
976 gPmAckFlags |= E_PM_ACKFLG_WAIT_GETMASTERKEY;
977
978 virtSrcAddr = (MS_VIRT)pPmPowerDownCfg;
979
980 // send to PM51
981 {
982 MB_Command.eRoleID = E_MBX_ROLE_PM;
983 MB_Command.eMsgType = E_MBX_MSG_TYPE_INSTANT;
984 MB_Command.u8Ctrl = 0; //0x01;
985 MB_Command.u8MsgClass = E_MBX_CLASS_PM_NOWAIT;
986 MB_Command.u8Index = PM_CMDIDX_GET_MASTERKEY;
987 MB_Command.u8ParameterCount = 4;
988 MB_Command.u8Parameters[0] = (MS_U8)(virtSrcAddr>>24);
989 MB_Command.u8Parameters[1] = (MS_U8)(virtSrcAddr>>16);
990 MB_Command.u8Parameters[2] = (MS_U8)(virtSrcAddr>>8);
991 MB_Command.u8Parameters[3] = (MS_U8)(virtSrcAddr&0x000000FFUL);
992
993 while(E_MBX_SUCCESS != (mbxResult = MDrv_MBX_SendMsg(&MB_Command)))
994 {
995 //Error Handling here:
996 }
997 }
998
999 do
1000 {
1001 if(MBX_Resendcnt<10)
1002 {
1003 mbxResult = _MDrv_PM_MailBoxHandler(&PmResult);
1004 MBX_Resendcnt++;
1005 }
1006 else
1007 {
1008 MBX_Resendcnt=0;
1009 while(E_MBX_SUCCESS != (mbxResult = MDrv_MBX_SendMsg(&MB_Command)))
1010 {
1011 //Error Handling here:
1012 }
1013 }
1014 }
1015 while((gPmAckFlags & E_PM_ACKFLG_WAIT_GETMASTERKEY) &&
1016 (mbxResult != E_MBX_ERR_TIME_OUT));
1017
1018 if( E_MBX_SUCCESS != mbxResult)
1019 {
1020 PmResult = E_PM_FAIL;
1021 PM_DBG_ERR("MDrv_PM_GetMasterKey Fail\n");
1022 }
1023 else
1024 {
1025 PmResult = E_PM_OK;
1026 PM_DBG_INFO("MDrv_PM_GetMasterKey OK\n");
1027 }
1028
1029 return PmResult;
1030 }
1031
MDrv_PM_GetDeviceID(MS_U8 * DeviceID)1032 PM_Result MDrv_PM_GetDeviceID(MS_U8 *DeviceID)
1033 {
1034 PM_Result PmResult = E_PM_FAIL;
1035
1036 _MDrv_PM_DummyMiuFifo();
1037
1038 MBX_Result mbxResult = E_MBX_UNKNOW_ERROR;
1039 MBX_Msg MB_Command;
1040
1041 MS_U32 MBX_Resendcnt = 0;
1042
1043 PM_DBG_FUNC();
1044
1045 memset((void*)&MB_Command, 0, sizeof(MBX_Msg));
1046
1047 gPmAckFlags |= E_PM_ACKFLG_WAIT_GETDEVICEID;
1048
1049 // send to PM51
1050 {
1051 MB_Command.eRoleID = E_MBX_ROLE_PM;
1052 MB_Command.eMsgType = E_MBX_MSG_TYPE_INSTANT;
1053 MB_Command.u8Ctrl = 0; //0x01;
1054 MB_Command.u8MsgClass = E_MBX_CLASS_PM_NOWAIT;
1055 MB_Command.u8Index = PM_CMDIDX_GET_DEVICEID;
1056 MB_Command.u8ParameterCount = 0;
1057
1058 while(E_MBX_SUCCESS != (mbxResult = MDrv_MBX_SendMsg(&MB_Command)))
1059 {
1060 //Error Handling here:
1061 }
1062 }
1063
1064 do
1065 {
1066 if(MBX_Resendcnt<10)
1067 {
1068 mbxResult = _MDrv_PM_MailBoxHandler(&PmResult);
1069 MBX_Resendcnt++;
1070 }
1071 else
1072 {
1073 MBX_Resendcnt=0;
1074 while(E_MBX_SUCCESS != (mbxResult = MDrv_MBX_SendMsg(&MB_Command)))
1075 {
1076 //Error Handling here:
1077 }
1078 }
1079 }
1080 while((gPmAckFlags & E_PM_ACKFLG_WAIT_GETDEVICEID) &&
1081 (mbxResult != E_MBX_ERR_TIME_OUT));
1082
1083 if( E_MBX_SUCCESS != mbxResult)
1084 {
1085 PmResult = E_PM_FAIL;
1086 PM_DBG_ERR("MDrv_PM_GetDeviceID Fail\n");
1087 }
1088 else
1089 {
1090 PmResult = E_PM_OK;
1091
1092 DeviceID[0] = gPmDeviceID[0];
1093 DeviceID[1] = gPmDeviceID[1];
1094 DeviceID[2] = gPmDeviceID[2];
1095 DeviceID[3] = gPmDeviceID[3];
1096 DeviceID[4] = gPmDeviceID[4];
1097 DeviceID[5] = gPmDeviceID[5];
1098
1099 PM_DBG_INFO("MDrv_PM_GetDeviceID OK\n");
1100 }
1101
1102 return PmResult;
1103 }
1104
MDrv_PM_GetPMMemAddr(MS_U8 * PmMemAddr)1105 PM_Result MDrv_PM_GetPMMemAddr(MS_U8 *PmMemAddr)
1106 {
1107 PM_Result PmResult = E_PM_FAIL;
1108
1109 _MDrv_PM_DummyMiuFifo();
1110
1111 MBX_Result mbxResult = E_MBX_UNKNOW_ERROR;
1112 MBX_Msg MB_Command;
1113
1114 MS_U32 MBX_Resendcnt = 0;
1115
1116 PM_DBG_FUNC();
1117
1118 memset((void*)&MB_Command, 0, sizeof(MBX_Msg));
1119
1120 gPmAckFlags |= E_PM_ACKFLG_WAIT_GETPMMEMADDR;
1121
1122 // send to PM51
1123 {
1124 MB_Command.eRoleID = E_MBX_ROLE_PM;
1125 MB_Command.eMsgType = E_MBX_MSG_TYPE_INSTANT;
1126 MB_Command.u8Ctrl = 0; //0x01;
1127 MB_Command.u8MsgClass = E_MBX_CLASS_PM_NOWAIT;
1128 MB_Command.u8Index = PM_CMDIDX_GET_PM_MEMADDR;
1129 MB_Command.u8ParameterCount = 0;
1130
1131 while(E_MBX_SUCCESS != (mbxResult = MDrv_MBX_SendMsg(&MB_Command)))
1132 {
1133
1134 //Error Handling here:
1135 }
1136 }
1137
1138 do
1139 {
1140 if(MBX_Resendcnt<10)
1141 {
1142 mbxResult = _MDrv_PM_MailBoxHandler(&PmResult);
1143 MBX_Resendcnt++;
1144 }
1145 else
1146 {
1147 MBX_Resendcnt=0;
1148 while(E_MBX_SUCCESS != (mbxResult = MDrv_MBX_SendMsg(&MB_Command)))
1149 {
1150 //Error Handling here:
1151 }
1152 }
1153 }
1154 while((gPmAckFlags & E_PM_ACKFLG_WAIT_GETPMMEMADDR) &&
1155 (mbxResult != E_MBX_ERR_TIME_OUT));
1156
1157 if( E_MBX_SUCCESS != mbxResult)
1158 {
1159 PmResult = E_PM_FAIL;
1160
1161 PM_DBG_ERR("MDrv_PM_GetPMMemAddr Fail\n");
1162 }
1163 else
1164 {
1165 PmResult = E_PM_OK;
1166
1167 PmMemAddr[0] = gPmMemAddr[0];
1168 PmMemAddr[1] = gPmMemAddr[1];
1169 PmMemAddr[2] = gPmMemAddr[2];
1170 PmMemAddr[3] = gPmMemAddr[3];
1171 PM_DBG_INFO("PmMemAddr[0] = 0x%x\n",PmMemAddr[0]);
1172 PM_DBG_INFO("PmMemAddr[1] = 0x%x\n",PmMemAddr[1]);
1173 PM_DBG_INFO("PmMemAddr[2] = 0x%x\n",PmMemAddr[2]);
1174 PM_DBG_INFO("PmMemAddr[3] = 0x%x\n",PmMemAddr[3]);
1175
1176 PM_DBG_INFO("MDrv_PM_GetPMMemAddr OK\n");
1177 }
1178
1179 return PmResult;
1180 }
1181
MDrv_PM_GetChipID(MS_U8 * ChipParam)1182 PM_Result MDrv_PM_GetChipID(MS_U8 *ChipParam)
1183 {
1184 PM_Result PmResult = E_PM_FAIL;
1185
1186 _MDrv_PM_DummyMiuFifo();
1187
1188 MBX_Result mbxResult = E_MBX_UNKNOW_ERROR;
1189 MBX_Msg MB_Command;
1190
1191 MS_U32 MBX_Resendcnt = 0;
1192
1193 PM_DBG_FUNC();
1194
1195 memset((void*)&MB_Command, 0, sizeof(MBX_Msg));
1196
1197 gPmAckFlags |= E_PM_ACKFLG_WAIT_GETCHIPID;
1198
1199 // send to PM51
1200 {
1201 MB_Command.eRoleID = E_MBX_ROLE_PM;
1202 MB_Command.eMsgType = E_MBX_MSG_TYPE_INSTANT;
1203 MB_Command.u8Ctrl = 0; //0x01;
1204 MB_Command.u8MsgClass = E_MBX_CLASS_PM_NOWAIT;
1205 MB_Command.u8Index = PM_CMDIDX_GET_CHIPID;
1206 MB_Command.u8ParameterCount = 0;
1207
1208 while(E_MBX_SUCCESS != (mbxResult = MDrv_MBX_SendMsg(&MB_Command)))
1209 {
1210 //Error Handling here:
1211 }
1212 }
1213
1214 do
1215 {
1216 if(MBX_Resendcnt<10)
1217 {
1218 mbxResult = _MDrv_PM_MailBoxHandler(&PmResult);
1219 MBX_Resendcnt++;
1220 }
1221 else
1222 {
1223 MBX_Resendcnt=0;
1224 while(E_MBX_SUCCESS != (mbxResult = MDrv_MBX_SendMsg(&MB_Command)))
1225 {
1226 //Error Handling here:
1227 }
1228 }
1229 }
1230 while((gPmAckFlags & E_PM_ACKFLG_WAIT_GETCHIPID) &&
1231 (mbxResult != E_MBX_ERR_TIME_OUT));
1232
1233 if( E_MBX_SUCCESS != mbxResult)
1234 {
1235 PmResult = E_PM_FAIL;
1236 PM_DBG_ERR("MDrv_PM_GetChipID Fail\n");
1237 }
1238 else
1239 {
1240 PmResult = E_PM_OK;
1241
1242 ChipParam[0] = gPmChipID[0];
1243 ChipParam[1] = gPmChipID[1];
1244 ChipParam[2] = gPmChipID[2];
1245 ChipParam[3] = gPmChipID[3];
1246
1247 PM_DBG_INFO("MDrv_PM_GetChipID OK\n");
1248 }
1249
1250 return PmResult;
1251 }
1252
1253 //-------------------------------------------------------------------------------------------------
1254 /// PM driver get information
1255 /// @return @ref PM_DrvInfo
1256 //-------------------------------------------------------------------------------------------------
MDrv_PM_GetInfo(void)1257 const PM_DrvInfo* MDrv_PM_GetInfo(void)
1258 {
1259 PM_DBG_FUNC();
1260
1261 PM_Result PmResult = E_PM_FAIL;
1262
1263 MBX_Result mbxResult = E_MBX_UNKNOW_ERROR;
1264 MBX_Msg MB_Command;
1265 MS_VIRT virtSrcAddr;
1266
1267 PM_DBG_FUNC();
1268
1269 memset((void*)&MB_Command, 0, sizeof(MBX_Msg));
1270
1271 gPmAckFlags |= E_PM_ACKFLG_WAIT_INFO;
1272
1273 virtSrcAddr = (MS_VIRT)(&_sPmDrvInfo);
1274
1275 // send to PM51
1276 {
1277 MB_Command.eRoleID = E_MBX_ROLE_PM;
1278 MB_Command.eMsgType = E_MBX_MSG_TYPE_INSTANT;
1279 MB_Command.u8Ctrl = 0; //0x01;
1280 MB_Command.u8MsgClass = E_MBX_CLASS_PM_NOWAIT;
1281 MB_Command.u8Index = PM_CMDIDX_GET_INFO;
1282 MB_Command.u8ParameterCount = 4;
1283 MB_Command.u8Parameters[0] = (MS_U8)(virtSrcAddr>>24);
1284 MB_Command.u8Parameters[1] = (MS_U8)(virtSrcAddr>>16);
1285 MB_Command.u8Parameters[2] = (MS_U8)(virtSrcAddr>>8);
1286 MB_Command.u8Parameters[3] = (MS_U8)(virtSrcAddr&0x000000FFUL);
1287
1288 while(E_MBX_SUCCESS != (mbxResult = MDrv_MBX_SendMsg(&MB_Command)))
1289 {
1290 //Error Handling here:
1291 }
1292 }
1293
1294 do
1295 {
1296
1297 mbxResult = _MDrv_PM_MailBoxHandler(&PmResult);
1298
1299 }
1300 while((gPmAckFlags & E_PM_ACKFLG_WAIT_INFO) &&
1301 (mbxResult != E_MBX_ERR_TIME_OUT));
1302
1303 if( E_MBX_SUCCESS != mbxResult)
1304 {
1305 PmResult = E_PM_FAIL;
1306 PM_DBG_ERR("MDrv_PM_GetInfo Fail\n");
1307 }
1308 else
1309 {
1310 PmResult = E_PM_OK;
1311 PM_DBG_INFO("MDrv_PM_GetInfo OK\n");
1312 }
1313
1314 //TODO
1315 return (&_sPmDrvInfo);
1316 }
1317
MDrv_PM_GPIOInit(MS_U16 u16GPIOIndex)1318 PM_Result MDrv_PM_GPIOInit(MS_U16 u16GPIOIndex)
1319 {
1320 u16GPIOIndex &= 0x1FCF; //Mask reserved GPIO 4, 5 and unused bits
1321
1322 PM_Result PmResult = E_PM_FAIL;
1323
1324 _MDrv_PM_DummyMiuFifo();
1325
1326 MBX_Result mbxResult = E_MBX_UNKNOW_ERROR;
1327 MBX_Msg MB_Command;
1328
1329 MS_U32 MBX_Resendcnt = 0;
1330
1331 PM_DBG_FUNC();
1332
1333 memset((void*)&MB_Command, 0, sizeof(MBX_Msg));
1334
1335 gPmAckFlags |= E_PM_ACKFLG_WAIT_GPIOINIT;
1336
1337 // send to PM51
1338 {
1339 MB_Command.eRoleID = E_MBX_ROLE_PM;
1340 MB_Command.eMsgType = E_MBX_MSG_TYPE_INSTANT;
1341 MB_Command.u8Ctrl = 0; //0x01;
1342 MB_Command.u8MsgClass = E_MBX_CLASS_PM_NOWAIT;
1343 MB_Command.u8Index = PM_CMDIDX_GPIO_INIT;
1344 MB_Command.u8ParameterCount = 2;
1345 MB_Command.u8Parameters[0] = (MS_U8)(u16GPIOIndex>>8);
1346 MB_Command.u8Parameters[1] = (MS_U8)(u16GPIOIndex&0x00FFUL);
1347 mbxResult = MDrv_MBX_SendMsg(&MB_Command);
1348 while(E_MBX_SUCCESS != mbxResult)
1349 {
1350 //Error Handling here:
1351 return E_PM_FAIL;
1352 }
1353 }
1354
1355 do
1356 {
1357 if(MBX_Resendcnt<10)
1358 {
1359 mbxResult = _MDrv_PM_MailBoxHandler(&PmResult);
1360 MBX_Resendcnt++;
1361 }
1362 else
1363 {
1364 MBX_Resendcnt=0;
1365 mbxResult = MDrv_MBX_SendMsg(&MB_Command);
1366 while(E_MBX_SUCCESS != mbxResult)
1367 {
1368 //Error Handling here:
1369 return E_PM_FAIL;
1370 }
1371 }
1372 }
1373 while((gPmAckFlags & E_PM_ACKFLG_WAIT_GPIOINIT) &&
1374 (mbxResult != E_MBX_ERR_TIME_OUT));
1375
1376 if( E_MBX_SUCCESS != mbxResult)
1377 {
1378 PmResult = E_PM_FAIL;
1379 PM_DBG_ERR("MDrv_PM_GPIOInit Fail\n");
1380 }
1381 else
1382 {
1383 PmResult = E_PM_OK;
1384 PM_DBG_INFO("MDrv_PM_GPIOInit OK\n");
1385 }
1386
1387 return PmResult;
1388 }
1389 //-------------------------------------------------------------------------------------------------
1390 /// Set debug level for debug message
1391 /// @param eLevel \b IN: E_PM_DBGLV_NONE/E_PM_DBGLV_ERR_ONLY/E_PM_DBGLV_INFO/E_PM_DBGLV_ALL
1392 /// @return @ref PM_Result
1393 //-------------------------------------------------------------------------------------------------
MDrv_PM_SetDbgLevel(PM_DbgLv eLevel)1394 PM_Result MDrv_PM_SetDbgLevel(PM_DbgLv eLevel)
1395 {
1396 PM_DBG_INFO("%s level: %u\n", __FUNCTION__, eLevel);
1397
1398 _gPmDbgLevel = eLevel;
1399 return E_PM_OK;
1400 }
1401
1402 //-------------------------------------------------------------------------------------------------
1403 /// Rtc Initialize
1404 /// @param pPmRtcParam \b IN: PM Rtc Parameters
1405 /// @return @ref PM_Result
1406 /// @note Please call MDrv_PM_GetInfo() first to init _sPmDrvInfo
1407 //-------------------------------------------------------------------------------------------------
MDrv_PM_RtcInit(PM_RtcParam * pPmRtcParam)1408 PM_Result MDrv_PM_RtcInit(PM_RtcParam *pPmRtcParam)
1409 {
1410 PM_Result PmResult = E_PM_FAIL;
1411
1412 _MDrv_PM_DummyMiuFifo();
1413
1414 //MBX_Result mbxResult = E_MBX_UNKNOW_ERROR;
1415 //MBX_Msg MB_Command;
1416 //MS_U32 u32SrcAddr;
1417 PM_RtcParam *pPmRtcVA = (PM_RtcParam*)_PA2VA((MS_VIRT)pPmRtcParam);
1418
1419 PM_DBG_FUNC();
1420
1421
1422 if(pPmRtcVA->u8PmRtcIndex > _sPmDrvInfo.u8PmSupRtcIdxMax)
1423 {
1424 PM_DBG_ERR("FAIL: Only support Max %d RTC(s)\n", _sPmDrvInfo.u8PmSupRtcIdxMax);
1425 return PmResult;
1426 }
1427 #if 1
1428 MS_VIRT virtBaseAddr;
1429 MS_PHY u32BaseSize;
1430 if(!MDrv_MMIO_GetBASE(&virtBaseAddr, &u32BaseSize,MS_MODULE_PM))
1431 {
1432 PM_DBG_ERR("Get IOMAP Base faill!\n");
1433 return PmResult;
1434 }
1435
1436 HAL_PM_SetIOMapBase(virtBaseAddr);
1437 #endif
1438
1439 _PM_ENTRY(_gu16PMResID);
1440 HAL_PM_RtcInit(pPmRtcVA->u8PmRtcIndex, pPmRtcVA->u32RtcCtrlWord);
1441 _PM_RETURN(_gu16PMResID);
1442 //HAL_PM_RtcInit(pPmRtcParam->u8PmRtcIndex, pPmRtcParam->u32RtcCtrlWord);
1443 PmResult = E_PM_OK;
1444
1445 #if 0
1446 memset((void*)&MB_Command, 0, sizeof(MBX_Msg));
1447
1448 gPmAckFlags |= E_PM_ACKFLG_WAIT_RTCINIT;
1449
1450 u32SrcAddr = (MS_U32)pPmRtcParam;
1451
1452 // send to PM51
1453 {
1454 MB_Command.eRoleID = E_MBX_ROLE_PM;
1455 MB_Command.eMsgType = E_MBX_MSG_TYPE_INSTANT;
1456 MB_Command.u8Ctrl = 0; //0x01;
1457 MB_Command.u8MsgClass = E_MBX_CLASS_PM_NOWAIT;
1458 MB_Command.u8Index = PM_CMDIDX_RTC_INIT;
1459 MB_Command.u8ParameterCount = 4;
1460 MB_Command.u8Parameters[0] = (MS_U8)(u32SrcAddr>>24);
1461 MB_Command.u8Parameters[1] = (MS_U8)(u32SrcAddr>>16);
1462 MB_Command.u8Parameters[2] = (MS_U8)(u32SrcAddr>>8);
1463 MB_Command.u8Parameters[3] = (MS_U8)(u32SrcAddr&0x000000FF);
1464
1465 while(E_MBX_SUCCESS != (mbxResult = MDrv_MBX_SendMsg(&MB_Command)))
1466 {
1467 //Error Handling here:
1468 }
1469 }
1470
1471 do
1472 {
1473 mbxResult = _MDrv_PM_MailBoxHandler(&PmResult);
1474 }
1475 while((gPmAckFlags & E_PM_ACKFLG_WAIT_RTCINIT) &&
1476 (mbxResult != E_MBX_ERR_TIME_OUT));
1477
1478 if( E_MBX_SUCCESS != mbxResult)
1479 {
1480 PmResult = E_PM_FAIL;
1481 PM_DBG_ERR("MDrv_PM_RtcInit Fail\n");
1482 }
1483 else
1484 {
1485 PmResult = E_PM_OK;
1486 PM_DBG_INFO("MDrv_PM_RtcInit OK\n");
1487 }
1488 #endif
1489
1490 return PmResult;
1491 }
1492
1493 //-------------------------------------------------------------------------------------------------
1494 /// Disable Rtc Init
1495 /// @param none \b IN: none
1496 /// @return @ref
1497 /// @note
1498 //-------------------------------------------------------------------------------------------------
MDrv_PM_Rtc_DisableInit(E_PM_RTC eRtc)1499 void MDrv_PM_Rtc_DisableInit(E_PM_RTC eRtc)
1500 {
1501 _PM_ENTRY(_gu16PMResID);
1502 HAL_PM_RTC_DisableInit(eRtc);
1503 _PM_RETURN(_gu16PMResID);
1504
1505 }
1506
1507 //-------------------------------------------------------------------------------------------------
1508 /// Rtc set counter
1509 /// @param pPmRtcParam \b IN: PM Rtc Parameters
1510 /// @return @ref PM_Result
1511 /// @note Please call MDrv_PM_GetInfo() first to init _sPmDrvInfo
1512 //-------------------------------------------------------------------------------------------------
MDrv_PM_RtcSetCounter(PM_RtcParam * pPmRtcParam)1513 PM_Result MDrv_PM_RtcSetCounter(PM_RtcParam *pPmRtcParam)
1514 {
1515 PM_Result PmResult = E_PM_FAIL;
1516
1517 _MDrv_PM_DummyMiuFifo();
1518
1519 //MBX_Result mbxResult = E_MBX_UNKNOW_ERROR;
1520 //MBX_Msg MB_Command;
1521 //MS_U32 u32SrcAddr;
1522 PM_RtcParam *pPmRtcVA = (PM_RtcParam*)_PA2VA((MS_VIRT)pPmRtcParam);
1523
1524 PM_DBG_FUNC();
1525
1526 if(pPmRtcVA->u8PmRtcIndex > _sPmDrvInfo.u8PmSupRtcIdxMax)
1527 {
1528 PM_DBG_ERR("FAIL: Only support Max %d RTC(s)\n", _sPmDrvInfo.u8PmSupRtcIdxMax);
1529 return PmResult;
1530 }
1531
1532 _PM_ENTRY(_gu16PMResID);
1533 HAL_PM_RtcSetCounter(pPmRtcVA->u8PmRtcIndex, pPmRtcVA->u32RtcSetCounter);
1534 _PM_RETURN(_gu16PMResID);
1535 PmResult=E_PM_OK;
1536
1537 #if 0
1538 memset((void*)&MB_Command, 0, sizeof(MBX_Msg));
1539
1540 gPmAckFlags |= E_PM_ACKFLG_WAIT_RTCSETCOUNTER;
1541
1542 u32SrcAddr = (MS_U32)pPmRtcParam;
1543
1544 // send to PM51
1545 {
1546 MB_Command.eRoleID = E_MBX_ROLE_PM;
1547 MB_Command.eMsgType = E_MBX_MSG_TYPE_INSTANT;
1548 MB_Command.u8Ctrl = 0; //0x01;
1549 MB_Command.u8MsgClass = E_MBX_CLASS_PM_NOWAIT;
1550 MB_Command.u8Index = PM_CMDIDX_RTC_SETCOUNTER;
1551 MB_Command.u8ParameterCount = 4;
1552 MB_Command.u8Parameters[0] = (MS_U8)(u32SrcAddr>>24);
1553 MB_Command.u8Parameters[1] = (MS_U8)(u32SrcAddr>>16);
1554 MB_Command.u8Parameters[2] = (MS_U8)(u32SrcAddr>>8);
1555 MB_Command.u8Parameters[3] = (MS_U8)(u32SrcAddr&0x000000FF);
1556
1557 while(E_MBX_SUCCESS != (mbxResult = MDrv_MBX_SendMsg(&MB_Command)))
1558 {
1559 //Error Handling here:
1560 }
1561 }
1562
1563 do
1564 {
1565 mbxResult = _MDrv_PM_MailBoxHandler(&PmResult);
1566 }
1567 while((gPmAckFlags & E_PM_ACKFLG_WAIT_RTCSETCOUNTER) &&
1568 (mbxResult != E_MBX_ERR_TIME_OUT));
1569
1570 if( E_MBX_SUCCESS != mbxResult)
1571 {
1572 PmResult = E_PM_FAIL;
1573 PM_DBG_ERR("MDrv_PM_RtcSetCounter Fail\n");
1574 }
1575 else
1576 {
1577 PmResult = E_PM_OK;
1578 PM_DBG_INFO("MDrv_PM_RtcSetCounter OK\n");
1579 }
1580 #endif
1581
1582 return PmResult;
1583 }
1584
1585 //-------------------------------------------------------------------------------------------------
1586 /// Rtc get counter
1587 /// @param pPmRtcParam \b IN: PM Rtc Parameters
1588 /// @return @ref PM_Result
1589 /// @note Please call MDrv_PM_GetInfo() first to init _sPmDrvInfo
1590 //-------------------------------------------------------------------------------------------------
MDrv_PM_RtcGetCounter(PM_RtcParam * pPmRtcParam)1591 PM_Result MDrv_PM_RtcGetCounter(PM_RtcParam *pPmRtcParam)
1592 {
1593 PM_Result PmResult = E_PM_FAIL;
1594
1595 _MDrv_PM_DummyMiuFifo();
1596
1597 //MBX_Result mbxResult = E_MBX_UNKNOW_ERROR;
1598 //MBX_Msg MB_Command;
1599 //MS_U32 u32SrcAddr;
1600 PM_RtcParam *pPmRtcVA = (PM_RtcParam*)_PA2VA((MS_VIRT)pPmRtcParam);
1601 PM_DBG_FUNC();
1602
1603 if(pPmRtcVA->u8PmRtcIndex > _sPmDrvInfo.u8PmSupRtcIdxMax)
1604 {
1605 PM_DBG_ERR("FAIL: Only support Max %d RTC(s)\n", _sPmDrvInfo.u8PmSupRtcIdxMax);
1606 return PmResult;
1607 }
1608
1609 _PM_ENTRY(_gu16PMResID);
1610 pPmRtcVA->u32RtcGetCounter = HAL_PM_RtcGetCounter(pPmRtcVA->u8PmRtcIndex);
1611 _PM_RETURN(_gu16PMResID);
1612 PmResult = E_PM_OK;
1613
1614 #if 0
1615 memset((void*)&MB_Command, 0, sizeof(MBX_Msg));
1616
1617 gPmAckFlags |= E_PM_ACKFLG_WAIT_RTCGETCOUNTER;
1618
1619 u32SrcAddr = (MS_U32)pPmRtcParam;
1620
1621 // send to PM51
1622 {
1623 MB_Command.eRoleID = E_MBX_ROLE_PM;
1624 MB_Command.eMsgType = E_MBX_MSG_TYPE_INSTANT;
1625 MB_Command.u8Ctrl = 0; //0x01;
1626 MB_Command.u8MsgClass = E_MBX_CLASS_PM_NOWAIT;
1627 MB_Command.u8Index = PM_CMDIDX_RTC_GETCOUNTER;
1628 MB_Command.u8ParameterCount = 4;
1629 MB_Command.u8Parameters[0] = (MS_U8)(u32SrcAddr>>24);
1630 MB_Command.u8Parameters[1] = (MS_U8)(u32SrcAddr>>16);
1631 MB_Command.u8Parameters[2] = (MS_U8)(u32SrcAddr>>8);
1632 MB_Command.u8Parameters[3] = (MS_U8)(u32SrcAddr&0x000000FF);
1633
1634 while(E_MBX_SUCCESS != (mbxResult = MDrv_MBX_SendMsg(&MB_Command)))
1635 {
1636 //Error Handling here:
1637 }
1638 }
1639
1640 do
1641 {
1642 mbxResult = _MDrv_PM_MailBoxHandler(&PmResult);
1643 }
1644 while((gPmAckFlags & E_PM_ACKFLG_WAIT_RTCGETCOUNTER) &&
1645 (mbxResult != E_MBX_ERR_TIME_OUT));
1646
1647 if( E_MBX_SUCCESS != mbxResult)
1648 {
1649 PmResult = E_PM_FAIL;
1650 PM_DBG_ERR("MDrv_PM_RtcGetCounter Fail\n");
1651 }
1652 else
1653 {
1654 PmResult = E_PM_OK;
1655 PM_DBG_INFO("MDrv_PM_RtcGetCounter OK\n");
1656 }
1657
1658 #endif
1659
1660 return PmResult;
1661 }
1662
1663 //-------------------------------------------------------------------------------------------------
1664 /// Rtc set match counter
1665 /// @param pPmRtcParam \b IN: PM Rtc Parameters
1666 /// @return @ref PM_Result
1667 /// @note Please call MDrv_PM_GetInfo() first to init _sPmDrvInfo
1668 //-------------------------------------------------------------------------------------------------
MDrv_PM_RtcSetMatchCounter(PM_RtcParam * pPmRtcParam)1669 PM_Result MDrv_PM_RtcSetMatchCounter(PM_RtcParam *pPmRtcParam)
1670 {
1671 PM_Result PmResult = E_PM_FAIL;
1672
1673 _MDrv_PM_DummyMiuFifo();
1674
1675 //MBX_Result mbxResult = E_MBX_UNKNOW_ERROR;
1676 //MBX_Msg MB_Command;
1677 //MS_U32 u32SrcAddr;
1678 PM_RtcParam *pPmRtcVA = (PM_RtcParam*)_PA2VA((MS_VIRT)pPmRtcParam);
1679 PM_DBG_FUNC();
1680
1681 if(pPmRtcVA->u8PmRtcIndex > _sPmDrvInfo.u8PmSupRtcIdxMax)
1682 {
1683 PM_DBG_ERR("FAIL: Only support Max %d RTC(s)\n", _sPmDrvInfo.u8PmSupRtcIdxMax);
1684 return PmResult;
1685 }
1686
1687 _PM_ENTRY(_gu16PMResID);
1688 HAL_PM_RtcSetMatchCounter(pPmRtcVA->u8PmRtcIndex, pPmRtcVA->u32RtcSetMatchCounter);
1689 _PM_RETURN(_gu16PMResID);
1690 PmResult = E_PM_OK;
1691
1692 #if 0
1693 memset((void*)&MB_Command, 0, sizeof(MBX_Msg));
1694
1695 gPmAckFlags |= E_PM_ACKFLG_WAIT_RTCSETMATCHCOUNTER;
1696
1697 u32SrcAddr = (MS_U32)pPmRtcParam;
1698
1699 // send to PM51
1700 {
1701 MB_Command.eRoleID = E_MBX_ROLE_PM;
1702 MB_Command.eMsgType = E_MBX_MSG_TYPE_INSTANT;
1703 MB_Command.u8Ctrl = 0; //0x01;
1704 MB_Command.u8MsgClass = E_MBX_CLASS_PM_NOWAIT;
1705 MB_Command.u8Index = PM_CMDIDX_RTC_SETMATCHCOUNTER;
1706 MB_Command.u8ParameterCount = 4;
1707 MB_Command.u8Parameters[0] = (MS_U8)(u32SrcAddr>>24);
1708 MB_Command.u8Parameters[1] = (MS_U8)(u32SrcAddr>>16);
1709 MB_Command.u8Parameters[2] = (MS_U8)(u32SrcAddr>>8);
1710 MB_Command.u8Parameters[3] = (MS_U8)(u32SrcAddr&0x000000FF);
1711
1712 while(E_MBX_SUCCESS != (mbxResult = MDrv_MBX_SendMsg(&MB_Command)))
1713 {
1714 //Error Handling here:
1715 }
1716 }
1717
1718 do
1719 {
1720 mbxResult = _MDrv_PM_MailBoxHandler(&PmResult);
1721 }
1722 while((gPmAckFlags & E_PM_ACKFLG_WAIT_RTCSETMATCHCOUNTER) &&
1723 (mbxResult != E_MBX_ERR_TIME_OUT));
1724
1725 if( E_MBX_SUCCESS != mbxResult)
1726 {
1727 PmResult = E_PM_FAIL;
1728 PM_DBG_ERR("MDrv_PM_RtcSetMatchCounter Fail\n");
1729 }
1730 else
1731 {
1732 PmResult = E_PM_OK;
1733 PM_DBG_INFO("MDrv_PM_RtcSetMatchCounter OK\n");
1734 }
1735 #endif
1736
1737 return PmResult;
1738 }
1739
1740
1741 //-------------------------------------------------------------------------------------------------
1742 /// Rtc get match counter
1743 /// @param pPmRtcParam \b IN: PM Rtc Parameters
1744 /// @return @ref PM_Result
1745 /// @note Please call MDrv_PM_GetInfo() first to init _sPmDrvInfo
1746 //-------------------------------------------------------------------------------------------------
MDrv_PM_RtcGetMatchCounter(PM_RtcParam * pPmRtcParam)1747 PM_Result MDrv_PM_RtcGetMatchCounter(PM_RtcParam *pPmRtcParam)
1748 {
1749 PM_Result PmResult = E_PM_FAIL;
1750
1751 _MDrv_PM_DummyMiuFifo();
1752
1753
1754 //MBX_Result mbxResult = E_MBX_UNKNOW_ERROR;
1755 //MBX_Msg MB_Command;
1756 //MS_U32 u32SrcAddr;
1757 PM_RtcParam *pPmRtcVA = (PM_RtcParam*)_PA2VA((MS_VIRT)pPmRtcParam);
1758 PM_DBG_FUNC();
1759
1760 if(pPmRtcVA->u8PmRtcIndex > _sPmDrvInfo.u8PmSupRtcIdxMax)
1761 {
1762 PM_DBG_ERR("FAIL: Only support Max %d RTC(s)\n", _sPmDrvInfo.u8PmSupRtcIdxMax);
1763 return PmResult;
1764 }
1765
1766 _PM_ENTRY(_gu16PMResID);
1767 pPmRtcVA->u32RtcGetMatchCounter = HAL_PM_RtcGetMatchCounter(pPmRtcVA->u8PmRtcIndex);
1768 _PM_RETURN(_gu16PMResID);
1769 PmResult = E_PM_OK;
1770
1771 #if 0
1772 memset((void*)&MB_Command, 0, sizeof(MBX_Msg));
1773
1774 gPmAckFlags |= E_PM_ACKFLG_WAIT_RTCGETMATCHCOUNTER;
1775
1776 u32SrcAddr = (MS_U32)pPmRtcParam;
1777
1778 // send to PM51
1779 {
1780 MB_Command.eRoleID = E_MBX_ROLE_PM;
1781 MB_Command.eMsgType = E_MBX_MSG_TYPE_INSTANT;
1782 MB_Command.u8Ctrl = 0; //0x01;
1783 MB_Command.u8MsgClass = E_MBX_CLASS_PM_NOWAIT;
1784 MB_Command.u8Index = PM_CMDIDX_RTC_GETMATCHCOUNTER;
1785 MB_Command.u8ParameterCount = 4;
1786 MB_Command.u8Parameters[0] = (MS_U8)(u32SrcAddr>>24);
1787 MB_Command.u8Parameters[1] = (MS_U8)(u32SrcAddr>>16);
1788 MB_Command.u8Parameters[2] = (MS_U8)(u32SrcAddr>>8);
1789 MB_Command.u8Parameters[3] = (MS_U8)(u32SrcAddr&0x000000FF);
1790
1791 while(E_MBX_SUCCESS != (mbxResult = MDrv_MBX_SendMsg(&MB_Command)))
1792 {
1793 //Error Handling here:
1794 }
1795 }
1796
1797 do
1798 {
1799 mbxResult = _MDrv_PM_MailBoxHandler(&PmResult);
1800 }
1801 while((gPmAckFlags & E_PM_ACKFLG_WAIT_RTCGETMATCHCOUNTER) &&
1802 (mbxResult != E_MBX_ERR_TIME_OUT));
1803
1804 if( E_MBX_SUCCESS != mbxResult)
1805 {
1806 PmResult = E_PM_FAIL;
1807 PM_DBG_ERR("MDrv_PM_RtcGetMatchCounter Fail\n");
1808 }
1809 else
1810 {
1811 PmResult = E_PM_OK;
1812 PM_DBG_INFO("MDrv_PM_RtcGetMatchCounter OK\n");
1813 }
1814 #endif
1815
1816 return PmResult;
1817 }
1818
1819
1820 ////////////////////////////////////////////////////////////////////////////////
1821 /// @brief \b Function \b Name: MDrv_PM_SetSPIOffsetForMCU
1822 /// @brief \b Function \b Description: MCU Reset and set code offset in spi
1823 /// @param pStatus \b Out: non
1824 ////////////////////////////////////////////////////////////////////////////////
MDrv_PM_SetSPIOffsetForMCU(MS_U32 BANK)1825 void MDrv_PM_SetSPIOffsetForMCU(MS_U32 BANK)
1826 {
1827 MS_VIRT virtBaseAddr;
1828 MS_PHY u32BaseSize;
1829 if(!MDrv_MMIO_GetBASE(&virtBaseAddr, &u32BaseSize,MS_MODULE_PM))
1830 {
1831 PM_DBG_ERR("Get IOMAP Base faill!\n");
1832 return ;
1833 }
1834
1835 HAL_PM_SetIOMapBase(virtBaseAddr);
1836
1837 HAL_PM_SetSPIOffsetForMCU(BANK);
1838
1839 }
1840
1841 ////////////////////////////////////////////////////////////////////////////////
1842 /// @brief \b Function \b Name: MDrv_PM_SetSRAMOffsetForMCU
1843 /// @brief \b Function \b Description: MCU Reset on MCU SRAM.
1844 /// @param pStatus \b Out: non
1845 ////////////////////////////////////////////////////////////////////////////////
MDrv_PM_SetSRAMOffsetForMCU(void)1846 void MDrv_PM_SetSRAMOffsetForMCU(void)
1847 {
1848 MS_VIRT virtBaseAddr;
1849 MS_PHY u32BaseSize;
1850 if(!MDrv_MMIO_GetBASE(&virtBaseAddr, &u32BaseSize, MS_MODULE_PM))
1851 {
1852 PM_DBG_ERR("Get IOMAP Base faill!\n");
1853 return ;
1854 }
1855
1856 HAL_PM_SetIOMapBase(virtBaseAddr);
1857
1858 HAL_PM_SetSRAMOffsetForMCU();
1859
1860 }
1861
1862 ////////////////////////////////////////////////////////////////////////////////
1863 /// @brief \b Function \b Name: MDrv_PM_SetDRAMOffsetForMCU
1864 /// @brief \b Function \b Description: MCU Reset and set code offset in DRAM.
1865 /// @return TRUE : succeed
1866 /// @return FALSE : fail
1867 ////////////////////////////////////////////////////////////////////////////////
MDrv_PM_SetDRAMOffsetForMCU(MS_U32 u32Offset)1868 MS_BOOL MDrv_PM_SetDRAMOffsetForMCU(MS_U32 u32Offset)
1869 {
1870 MS_VIRT virtBaseAddr;
1871 MS_PHY u32BaseSize;
1872 MS_BOOL bRet;
1873 if(!MDrv_MMIO_GetBASE(&virtBaseAddr, &u32BaseSize,MS_MODULE_PM))
1874 {
1875 PM_DBG_ERR("Get IOMAP Base faill!\n");
1876 return FALSE;
1877 }
1878
1879 HAL_PM_SetIOMapBase(virtBaseAddr);
1880
1881 bRet = HAL_PM_SetDRAMOffsetForMCU(u32Offset);
1882
1883 return bRet;
1884 }
1885
1886 ////////////////////////////////////////////////////////////////////////////////
1887 /// @brief \b Function \b Name: MDrv_PM_PowerOnMode
1888 /// @brief \b Function \b Description: Return power on mode
1889 /// @param pStatus \b Out: PM_PowerOnMode
1890 ////////////////////////////////////////////////////////////////////////////////
MDrv_PM_PowerOnMode(void)1891 PM_PowerOnMode MDrv_PM_PowerOnMode(void)
1892 {
1893 PM_PowerOnMode PowerOnMode = E_PM_POWERON_ACON;
1894 MS_VIRT virtBaseAddr;
1895 MS_PHY u32BaseSize;
1896 if(!MDrv_MMIO_GetBASE(&virtBaseAddr, &u32BaseSize,MS_MODULE_PM))
1897 {
1898 PM_DBG_ERR("Get IOMAP Base faill!\n");
1899 return PowerOnMode;
1900 }
1901
1902 HAL_PM_SetIOMapBase(virtBaseAddr);
1903 PowerOnMode =(PM_PowerOnMode) HAL_PM_PowerOnMode();
1904 return PowerOnMode ;
1905
1906 }
1907
1908 ////////////////////////////////////////////////////////////////////////////////
1909 /// @brief \b Function \b Name: MDrv_PM_GetWakeupSource
1910 /// @brief \b Function \b Description: Return wakeup source
1911 /// @param pStatus \b Out: PM_WakeupSource
1912 ////////////////////////////////////////////////////////////////////////////////
MDrv_PM_GetWakeupSource(void)1913 PM_WakeupSource MDrv_PM_GetWakeupSource(void)
1914 {
1915 PM_WakeupSource WakeupSource = E_PM_WAKEUPSRC_NONE;
1916 MS_VIRT virtBaseAddr;
1917 MS_PHY u32BaseSize;
1918 if(!MDrv_MMIO_GetBASE(&virtBaseAddr, &u32BaseSize,MS_MODULE_PM))
1919 {
1920 PM_DBG_ERR("Get IOMAP Base fail!\n");
1921 return WakeupSource;
1922 }
1923
1924 HAL_PM_SetIOMapBase(virtBaseAddr);
1925 WakeupSource=(PM_WakeupSource) HAL_PM_GetWakeupSource();
1926 return WakeupSource;
1927
1928 }
1929
1930 ////////////////////////////////////////////////////////////////////////////////
1931 /// @brief \b Function \b Name: MDrv_PM_GetWakeupKey
1932 /// @brief \b Function \b Description: Return wakeup key
1933 /// @param \b Out: MS_U8 wakeup key value
1934 ////////////////////////////////////////////////////////////////////////////////
MDrv_PM_GetWakeupKey(void)1935 MS_U8 MDrv_PM_GetWakeupKey(void)
1936 {
1937 MS_U8 u8WakeupKey = 0x00;
1938 MS_VIRT virtBaseAddr;
1939 MS_PHY u32BaseSize;
1940 if(!MDrv_MMIO_GetBASE(&virtBaseAddr, &u32BaseSize,MS_MODULE_PM))
1941 {
1942 PM_DBG_ERR("Get IOMAP Base fail!\n");
1943 return u8WakeupKey;
1944 }
1945
1946 HAL_PM_SetIOMapBase(virtBaseAddr);
1947 u8WakeupKey=(MS_U8) HAL_PM_GetWakeupKey();
1948 return u8WakeupKey;
1949 }
1950
1951 //-------------------------------------------------------------------------------------------------
1952 /// PM Get Extra Sram Data
1953 /// @param pPmExtraSramData \b IN: PM get extra sram data configuration
1954 /// @return @ref PM_Result
1955 //-------------------------------------------------------------------------------------------------
1956
MDrv_PM_GetExtraSramData(PM_ExtraSramData * pPmExtraSramData)1957 PM_Result MDrv_PM_GetExtraSramData(PM_ExtraSramData *pPmExtraSramData)
1958 {
1959 PM_Result PmResult = E_PM_FAIL;
1960 MBX_Result mbxResult = E_MBX_UNKNOW_ERROR;
1961 MBX_Msg MB_Command;
1962 MS_VIRT virtSrcAddr;
1963
1964 MS_U32 MBX_Resendcnt = 0;
1965 PM_ExtraSramData *pPmExtraSramDataVA = (PM_ExtraSramData*)_PA2VA((MS_VIRT)pPmExtraSramData);
1966
1967 if (pPmExtraSramDataVA->u16Offset + pPmExtraSramDataVA->u16DataLen > 512)
1968 {
1969 PM_DBG_ERR("Excess Extra SRAM size (512 bytes)\n");
1970 return E_PM_FAIL;
1971 }
1972
1973 _MDrv_PM_DummyMiuFifo();
1974
1975 PM_DBG_FUNC();
1976
1977 memset((void*)&MB_Command, 0, sizeof(MBX_Msg));
1978
1979 gPmAckFlags |= E_PM_ACKFLG_WAIT_GETEXTRASRAMDATA;
1980
1981 virtSrcAddr = (MS_VIRT)pPmExtraSramData;
1982
1983 // send to PM51
1984 {
1985 MB_Command.eRoleID = E_MBX_ROLE_PM;
1986 MB_Command.eMsgType = E_MBX_MSG_TYPE_INSTANT;
1987 MB_Command.u8Ctrl = 0; //0x01;
1988 MB_Command.u8MsgClass = E_MBX_CLASS_PM_NOWAIT;
1989 MB_Command.u8Index = PM_CMDIDX_GETEXTRASRAMDATA;
1990 MB_Command.u8ParameterCount = 4;
1991 MB_Command.u8Parameters[0] = (MS_U8)(virtSrcAddr>>24);
1992 MB_Command.u8Parameters[1] = (MS_U8)(virtSrcAddr>>16);
1993 MB_Command.u8Parameters[2] = (MS_U8)(virtSrcAddr>>8);
1994 MB_Command.u8Parameters[3] = (MS_U8)(virtSrcAddr&0x000000FFUL);
1995
1996 while(E_MBX_SUCCESS != (mbxResult = MDrv_MBX_SendMsg(&MB_Command)))
1997 {
1998 //Error Handling here:
1999 }
2000 }
2001
2002 // Waiting for PM51 Power Management initialization done
2003 do
2004 {
2005 if(MBX_Resendcnt<10)
2006 {
2007 mbxResult = _MDrv_PM_MailBoxHandler(&PmResult);
2008 MBX_Resendcnt++;
2009 }
2010 else
2011 {
2012 MBX_Resendcnt=0;
2013 while(E_MBX_SUCCESS != (mbxResult = MDrv_MBX_SendMsg(&MB_Command)))
2014 {
2015 //Error Handling here:
2016 }
2017 }
2018 }
2019 while((gPmAckFlags & E_PM_ACKFLG_WAIT_GETEXTRASRAMDATA) &&
2020 (mbxResult != E_MBX_ERR_TIME_OUT));
2021
2022 if( E_MBX_SUCCESS != mbxResult)
2023 {
2024 PmResult = E_PM_FAIL;
2025 PM_DBG_ERR("MDrv_PM_GetExtraSramData Fail\n");
2026 }
2027 else
2028 {
2029 PmResult = E_PM_OK;
2030 PM_DBG_INFO("MDrv_PM_GetExtraSramData OK\n");
2031 }
2032
2033 return PmResult;
2034 }
2035
2036 //-------------------------------------------------------------------------------------------------
2037 /// PM Set Extra Sram Data
2038 /// @param pPmExtraSramData \b IN: PM set extra sram data configuration
2039 /// @return @ref PM_Result
2040 //-------------------------------------------------------------------------------------------------
2041
MDrv_PM_SetExtraSramData(PM_ExtraSramData * pPmExtraSramData)2042 PM_Result MDrv_PM_SetExtraSramData(PM_ExtraSramData *pPmExtraSramData)
2043 {
2044 PM_Result PmResult = E_PM_FAIL;
2045 MBX_Result mbxResult = E_MBX_UNKNOW_ERROR;
2046 MBX_Msg MB_Command;
2047 MS_VIRT virtSrcAddr;
2048
2049 MS_U32 MBX_Resendcnt = 0;
2050 PM_ExtraSramData *pPmExtraSramDataVA = (PM_ExtraSramData*)_PA2VA((MS_VIRT)pPmExtraSramData);
2051
2052 if (pPmExtraSramDataVA->u16Offset + pPmExtraSramDataVA->u16DataLen > 512)
2053 {
2054 PM_DBG_ERR("Excess Extra SRAM size (512 bytes)\n");
2055 return E_PM_FAIL;
2056 }
2057
2058 _MDrv_PM_DummyMiuFifo();
2059
2060 PM_DBG_FUNC();
2061
2062 memset((void*)&MB_Command, 0, sizeof(MBX_Msg));
2063
2064 gPmAckFlags |= E_PM_ACKFLG_WAIT_SETEXTRASRAMDATA;
2065
2066 virtSrcAddr = (MS_VIRT)pPmExtraSramData;
2067
2068 // send to PM51
2069 {
2070 MB_Command.eRoleID = E_MBX_ROLE_PM;
2071 MB_Command.eMsgType = E_MBX_MSG_TYPE_INSTANT;
2072 MB_Command.u8Ctrl = 0; //0x01;
2073 MB_Command.u8MsgClass = E_MBX_CLASS_PM_NOWAIT;
2074 MB_Command.u8Index = PM_CMDIDX_SETEXTRASRAMDATA;
2075 MB_Command.u8ParameterCount = 4;
2076 MB_Command.u8Parameters[0] = (MS_U8)(virtSrcAddr>>24);
2077 MB_Command.u8Parameters[1] = (MS_U8)(virtSrcAddr>>16);
2078 MB_Command.u8Parameters[2] = (MS_U8)(virtSrcAddr>>8);
2079 MB_Command.u8Parameters[3] = (MS_U8)(virtSrcAddr&0x000000FFUL);
2080
2081 while(E_MBX_SUCCESS != (mbxResult = MDrv_MBX_SendMsg(&MB_Command)))
2082 {
2083 //Error Handling here:
2084 }
2085 }
2086
2087 // Waiting for PM51 Power Management initialization done
2088 do
2089 {
2090 if(MBX_Resendcnt<10)
2091 {
2092 mbxResult = _MDrv_PM_MailBoxHandler(&PmResult);
2093 MBX_Resendcnt++;
2094 }
2095 else
2096 {
2097 MBX_Resendcnt=0;
2098 while(E_MBX_SUCCESS != (mbxResult = MDrv_MBX_SendMsg(&MB_Command)))
2099 {
2100 //Error Handling here:
2101 }
2102 }
2103 }
2104 while((gPmAckFlags & E_PM_ACKFLG_WAIT_SETEXTRASRAMDATA) &&
2105 (mbxResult != E_MBX_ERR_TIME_OUT));
2106
2107 if( E_MBX_SUCCESS != mbxResult)
2108 {
2109 PmResult = E_PM_FAIL;
2110 PM_DBG_ERR("MDrv_PM_SetExtraSramData Fail\n");
2111 }
2112 else
2113 {
2114 PmResult = E_PM_OK;
2115 PM_DBG_INFO("MDrv_PM_SetExtraSramData OK\n");
2116 }
2117
2118 return PmResult;
2119 }
2120
2121 ////////////////////////////////////////////////////////////////////////////////
2122 /// @brief \b Function \b Name: MDrv_PM_Disable51
2123 /// @brief \b Function \b Description: Disable PM51
2124 /// @return @ref PM_Result
2125 ////////////////////////////////////////////////////////////////////////////////
MDrv_PM_Disable51(void)2126 PM_Result MDrv_PM_Disable51(void)
2127 {
2128 #if defined(__mips__) || defined(__arm__)
2129
2130
2131 MS_VIRT virtBaseAddr;
2132 MS_PHY u32BaseSize = 0;
2133
2134 if(!MDrv_MMIO_GetBASE(&virtBaseAddr, &u32BaseSize, MS_MODULE_PM))
2135 {
2136 PM_DBG_ERR("%s Get IOMAP Base faill!\n", __FUNCTION__);
2137 return E_PM_FAIL;
2138 }
2139 HAL_PM_SetIOMapBase(virtBaseAddr);
2140 HAL_PM_Disable51();
2141 #endif
2142 return E_PM_OK;
2143 }
2144
2145
2146
2147 //-------------------------------------------------------------------------------------------------
2148 /// PM PWM MailBox Handler
2149 /// @param pData \b IN: mailbox data configuration
2150 /// @return @ref MBX_Result
2151 //-------------------------------------------------------------------------------------------------
_MDrv_PM_PWM_MailBoxHandler(void * pData)2152 MBX_Result _MDrv_PM_PWM_MailBoxHandler(void *pData)
2153 {
2154 MBX_Msg MB_Command;
2155
2156 MBX_Result mbxResult = E_MBX_UNKNOW_ERROR;
2157
2158 PM_DBG_FUNC();
2159
2160 mbxResult = MDrv_MBX_RecvMsg(E_MBX_CLASS_PM_PWM_WAIT, &MB_Command, PM_MBX_TIMEOUT/*ms*/, MBX_CHECK_NORMAL_MSG);
2161 if (E_MBX_ERR_TIME_OUT == mbxResult)
2162 {
2163 return mbxResult;
2164 }
2165
2166 if (E_MBX_SUCCESS == mbxResult)
2167 {
2168 if ((MB_Command.u8Ctrl == 0) || (MB_Command.u8Ctrl == 1))
2169 {
2170 PM_DBG_INFO("Get PM PWM command: 0x%02x.\n", MB_Command.u8Index);
2171 if(MB_Command.u8Index == PM_CMDIDX_ACK_51ToAEON )
2172 {
2173 PM_DBG_INFO("\r\n PM_CMDIDX_ACK_51ToAEON.\n");
2174 PM_DBG_INFO("GetPM_CMDIDX_PWM_INIT 0x%02x.\n", PM_CMDIDX_PWM_INIT);
2175 PM_DBG_INFO("Get MB_Command.u8Parameters[0] 0x%02x.\n", MB_Command.u8Parameters[0]);
2176 PM_DBG_INFO("Get MB_Command.u8Parameters[1] 0x%02x.\n", MB_Command.u8Parameters[1]);
2177 switch(MB_Command.u8Parameters[0])
2178 {
2179 case PM_CMDIDX_PWM_INIT:
2180 *((PM_Result*)pData) = (PM_Result)MB_Command.u8Parameters[1];
2181 gPmPWMAckFlags &= (PM_PWM_AckFlags)(~E_PM_PWM_ACKFLG_WAIT_INIT);
2182 break;
2183 case PM_CMDIDX_PWM_CONFIG:
2184 *((PM_Result*)pData) = (PM_Result)MB_Command.u8Parameters[1];
2185 gPmPWMAckFlags &= (PM_PWM_AckFlags)(~E_PM_PWM_ACKFLG_WAIT_CONF);
2186 break;
2187 case PM_CMDIDX_PWM_IRRECORD_TRANSMIT :
2188 *((PM_Result*)pData) = (PM_Result)MB_Command.u8Parameters[1];
2189 gPmPWMAckFlags &= (PM_PWM_AckFlags)(~E_PM_PWM_ACKFLG_WAIT_IRRECORD_TRANSMIT);
2190 break;
2191 case PM_CMDIDX_PWM_IRRECORD_RECEIVED_REQUIRE :
2192 *((PM_Result*)pData) = (PM_Result)MB_Command.u8Parameters[1];
2193 gPmPWMAckFlags &= (PM_PWM_AckFlags)(~E_PM_PWM_ACKFLG_WAIT_IRRECORD_RECIEVE_REQUIRE);
2194 break;
2195 case PM_CMDIDX_PWM_IRRECORD_RECEIVED_COMPLETE :
2196 *((PM_Result*)pData) = (PM_Result)MB_Command.u8Parameters[1];
2197 gPmPWMAckFlags &= (PM_PWM_AckFlags)(~E_PM_PWM_ACKFLG_WAIT_IRRECORD_RECIEVE_COMPLETE);
2198 break;
2199 case PM_CMDIDX_PWM_IRRECORD_RECEIVED_SETCALLBACK:
2200 *((PM_Result*)pData) = (PM_Result)MB_Command.u8Parameters[1];
2201 gPmPWMAckFlags &= (PM_PWM_AckFlags)(~E_PM_PWM_ACKFLG_WAIT_IRRECORD_SETCALLBACK);
2202 break;
2203 case PM_CMDIDX_PWM_IRRECORD_RECEIVED_EXIT:
2204 *((PM_Result*)pData) = (PM_Result)MB_Command.u8Parameters[1];
2205 gPmPWMAckFlags &= (PM_PWM_AckFlags)(~E_PM_PWM_ACKFLG_WAIT_IRRECORD_RECIEVE_EXIT);
2206 break;
2207 default:
2208 break;
2209 }
2210 }
2211 }
2212 }
2213
2214 return mbxResult;
2215 }
2216 //-------------------------------------------------------------------------------------------------
2217 /// PM PWM MailBox Handler
2218 /// @param pData \b IN: mailbox data configuration
2219 /// @param pbAddToQueue \b IN: add to queue
2220 /// @return @ref MBX_Result
2221 //-------------------------------------------------------------------------------------------------
_PM_PWM_MailBoxCallbackHandler(MBX_Msg * pMsg,MS_BOOL * pbAddToQueue)2222 static void _PM_PWM_MailBoxCallbackHandler( MBX_Msg *pMsg, MS_BOOL *pbAddToQueue)
2223 {
2224 MS_U32 u32Memoryadrr =0 ;
2225 MS_U16 u16datalen =0;
2226 MS_U8 i=0;
2227
2228 PM_DBG_FUNC();
2229
2230 *pbAddToQueue = FALSE; //no need to add to queue
2231
2232 if(!pMsg) return;
2233
2234 if(pMsg->u8MsgClass != E_MBX_CLASS_PM_PWM_NOWAIT)
2235 {
2236 PM_DBG_ERR("Invalid Message Class!\n");
2237 return;
2238 }
2239
2240 // check control type
2241 if ((pMsg->u8Ctrl != 4) && (pMsg->u8Ctrl != 5))
2242 {
2243 PM_DBG_ERR("Control: 0x%02x\n", pMsg->u8Ctrl);
2244 PM_DBG_INFO("Not Implemented!\n");
2245 return;
2246 }
2247 PM_DBG_INFO("Get IR record command: 0x%02x\n", pMsg->u8Index);
2248 PM_DBG_INFO("Parameter[0]=%d\n", pMsg->u8Parameters[0]);
2249 PM_DBG_INFO("Parameter[1]=%d\n", pMsg->u8Parameters[1]);
2250 PM_DBG_INFO("Parameter[2]=%d\n", pMsg->u8Parameters[2]);
2251 PM_DBG_INFO("Parameter[3]=%d\n", pMsg->u8Parameters[3]);
2252 PM_DBG_INFO("Parameter[4]=%d\n", pMsg->u8Parameters[4]);
2253 PM_DBG_INFO("Parameter[5]=%d\n", pMsg->u8Parameters[5]);
2254
2255 for(i=0; i<4; i++)
2256 {
2257 u32Memoryadrr = (u32Memoryadrr<<8) | (MS_U8)(pMsg->u8Parameters[i]);
2258 }
2259 for(i=0; i<2; i++)
2260 {
2261 u16datalen = (u16datalen<<8)|(MS_U8)(pMsg->u8Parameters[i+4]);
2262 }
2263 if (pMsg->u8Index == PM_CMDIDX_PWM_IRRECORD_RECEIVED_COMPLETE)
2264 {
2265 if(gfIRRecordCallback)
2266 {
2267 gfIRRecordCallback(u32Memoryadrr, u16datalen);
2268 }
2269 }
2270
2271 return;
2272 }
2273
2274 //-------------------------------------------------------------------------------------------------
2275 /// PM PWM driver initialize
2276 /// @param u8PWM \b IN: PM pwm initialize configuration
2277 /// @return @ref PM_Result
2278 //-------------------------------------------------------------------------------------------------
MDrv_PM_PWM_Init(MS_U8 u8PWM)2279 PM_Result MDrv_PM_PWM_Init(MS_U8 u8PWM)
2280 {
2281 PM_Result PmResult = E_PM_FAIL;
2282 MBX_Result mbxResult = E_MBX_UNKNOW_ERROR;
2283 MBX_Msg MB_Command;
2284 MS_VIRT virtSrcAddr;
2285
2286 MS_U32 MBX_Resendcnt = 0;
2287
2288 _MDrv_PM_DummyMiuFifo();
2289
2290 PM_DBG_FUNC();
2291 memset((void*)&MB_Command, 0, sizeof(MBX_Msg));
2292
2293 gPmPWMAckFlags |= E_PM_PWM_ACKFLG_WAIT_INIT;
2294
2295
2296 mbxResult = MDrv_MBX_RegisterMSG(E_MBX_CLASS_PM_PWM_WAIT,PM_MBX_QUEUESIZE);
2297 if(mbxResult!=E_MBX_SUCCESS)
2298 {
2299 PM_DBG_ERR("Mailbox registered fails!\n");
2300 return E_PM_FAIL;
2301 }
2302 virtSrcAddr = (MS_VIRT)u8PWM;
2303 // send to PM51
2304 {
2305 MB_Command.eRoleID = E_MBX_ROLE_PM;
2306 MB_Command.eMsgType = E_MBX_MSG_TYPE_INSTANT;
2307 MB_Command.u8Ctrl = 0; //0x01;
2308 MB_Command.u8MsgClass = E_MBX_CLASS_PM_PWM_NOWAIT;
2309 MB_Command.u8Index = PM_CMDIDX_PWM_INIT;
2310 MB_Command.u8ParameterCount = 1;
2311 MB_Command.u8Parameters[0] = (MS_U8)(virtSrcAddr&0x000000FFUL);
2312
2313 mbxResult = MDrv_MBX_SendMsg(&MB_Command);
2314 while(E_MBX_SUCCESS != mbxResult)
2315 {
2316 //Error Handling here:
2317 return E_PM_FAIL;
2318 }
2319 }
2320
2321 // Waiting for PM51 PWM initialization done
2322 do
2323 {
2324 if(MBX_Resendcnt<10)
2325 {
2326 mbxResult = _MDrv_PM_PWM_MailBoxHandler(&PmResult);
2327 MBX_Resendcnt++;
2328 }
2329 else
2330 {
2331 MBX_Resendcnt=0;
2332 mbxResult = MDrv_MBX_SendMsg(&MB_Command);
2333 while(E_MBX_SUCCESS != mbxResult)
2334 {
2335 //Error Handling here:
2336 return E_PM_FAIL;
2337 }
2338 }
2339 }
2340 while((gPmPWMAckFlags & E_PM_PWM_ACKFLG_WAIT_INIT)
2341 &&(mbxResult != E_MBX_ERR_TIME_OUT));
2342
2343 if( E_MBX_SUCCESS != mbxResult)
2344 {
2345 PmResult = E_PM_FAIL;
2346 PM_DBG_ERR("MDrv_PM_PWM_Init Fail\n");
2347 }
2348 else
2349 {
2350 PmResult = E_PM_OK;
2351 PM_DBG_INFO("MDrv_PM_PWM_Init OK\n");
2352 }
2353
2354 return PmResult;
2355
2356 }
2357
2358
2359 //-------------------------------------------------------------------------------------------------
2360 /// PM PWM driver config
2361 /// @param pPmPWMCfg \b IN: PM PWM configuration
2362 /// @return @ref PM_Result
2363 //-------------------------------------------------------------------------------------------------
MDrv_PM_PWM_Config(PWMSimIR_CFG * pPWMSimIRCfg)2364 PM_Result MDrv_PM_PWM_Config(PWMSimIR_CFG *pPWMSimIRCfg)
2365 {
2366 PM_Result PmResult = E_PM_FAIL;
2367 MBX_Result mbxResult = E_MBX_UNKNOW_ERROR;
2368 MBX_Msg MB_Command;
2369
2370 MS_U32 MBX_Resendcnt = 0;
2371
2372 _MDrv_PM_DummyMiuFifo();
2373
2374 PM_DBG_FUNC();
2375 memset((void*)&MB_Command, 0, sizeof(MBX_Msg));
2376
2377 gPmPWMAckFlags |= E_PM_PWM_ACKFLG_WAIT_CONF;
2378
2379 // send to PM51
2380 {
2381 MB_Command.eRoleID = E_MBX_ROLE_PM;
2382 MB_Command.eMsgType = E_MBX_MSG_TYPE_INSTANT;
2383 MB_Command.u8Ctrl = 0; //0x01;
2384 MB_Command.u8MsgClass = E_MBX_CLASS_PM_PWM_NOWAIT;
2385 MB_Command.u8Index = PM_CMDIDX_PWM_CONFIG;
2386 MB_Command.u8ParameterCount = 8;
2387 MB_Command.u8Parameters[0] = (MS_U8)pPWMSimIRCfg->u8IREncodeMode;
2388 MB_Command.u8Parameters[1] = (MS_U8)pPWMSimIRCfg->u8Customercode1;
2389 MB_Command.u8Parameters[2] = (MS_U8)pPWMSimIRCfg->u8Customercode2;
2390 MB_Command.u8Parameters[3] = (MS_U8)pPWMSimIRCfg->u8IRKeycode;
2391 MB_Command.u8Parameters[4] = (MS_U8)pPWMSimIRCfg->u8IRRepeat;
2392 MB_Command.u8Parameters[5] = (MS_U8)pPWMSimIRCfg->u8Reserved0;
2393 MB_Command.u8Parameters[6] = (MS_U8)pPWMSimIRCfg->u8Reserved1;
2394 MB_Command.u8Parameters[7] = (MS_U8)pPWMSimIRCfg->u8Reserved2;
2395 mbxResult = MDrv_MBX_SendMsg(&MB_Command);
2396
2397 while(E_MBX_SUCCESS != mbxResult)
2398 {
2399 //Error Handling here:
2400 return E_PM_FAIL;
2401 }
2402 }
2403 // Waiting for PM51 PWM config done
2404 do
2405 {
2406 if(MBX_Resendcnt<10)
2407 {
2408 mbxResult = _MDrv_PM_PWM_MailBoxHandler(&PmResult);
2409 MBX_Resendcnt++;
2410 }
2411 else
2412 {
2413 MBX_Resendcnt=0;
2414 mbxResult = MDrv_MBX_SendMsg(&MB_Command);
2415 while(E_MBX_SUCCESS != mbxResult)
2416 {
2417 //Error Handling here:
2418 return E_PM_FAIL;
2419 }
2420 }
2421 }
2422 while((gPmPWMAckFlags & E_PM_PWM_ACKFLG_WAIT_CONF)
2423 &&(mbxResult != E_MBX_ERR_TIME_OUT));
2424
2425 if( E_MBX_SUCCESS != mbxResult)
2426 {
2427 PmResult = E_PM_FAIL;
2428 PM_DBG_ERR("MDrv_PM_PWM_Config Fail\n");
2429 }
2430 else
2431 {
2432 PmResult = E_PM_OK;
2433 PM_DBG_INFO("MDrv_PM_PWM_Config OK\n");
2434 }
2435
2436 return PmResult;
2437
2438 }
2439
2440
2441 //-------------------------------------------------------------------------------------------------
2442 /// IR record initial
2443 /// @param None
2444 /// @return @ref PM_Result
2445 //-------------------------------------------------------------------------------------------------
MDrv_PM_PWM_IRRecord_Init(void)2446 PM_Result MDrv_PM_PWM_IRRecord_Init(void)
2447 {
2448 MBX_Result MbxResult = E_MBX_UNKNOW_ERROR;
2449
2450 PM_DBG_INFO(" ........MDrv_IR_Record_Init ....\n");
2451 MbxResult = MDrv_MBX_RegisterMSGWithCallBack(E_MBX_CLASS_PM_PWM_NOWAIT,PM_MBX_QUEUESIZE,_PM_PWM_MailBoxCallbackHandler);
2452 if(MbxResult!=E_MBX_SUCCESS)
2453 {
2454 PM_DBG_ERR("Mailbox registered with callback fails!\n");
2455 return E_PM_FAIL;
2456 }
2457
2458 MbxResult = MDrv_MBX_RegisterMSG(E_MBX_CLASS_PM_PWM_WAIT,PM_MBX_QUEUESIZE);
2459 if(MbxResult != E_MBX_SUCCESS)
2460 {
2461 PM_DBG_ERR("Mailbox registered fails!\n");
2462 return E_PM_FAIL;
2463 }
2464
2465 return E_PM_OK;
2466
2467 }
2468 //-------------------------------------------------------------------------------------------------
2469 /// Set PM Recieved IR Pulse require
2470 /// @param u32BufferAddr \b IN: Buffer Address
2471 /// @param u16BufferSize \b IN: Buffer Size
2472 /// @return @ref PM_Result
2473 //-------------------------------------------------------------------------------------------------
MDrv_PM_PWM_IRRecord_Receive_Require(MS_U32 u32BufferAddr,MS_U16 u16BufferSize)2474 PM_Result MDrv_PM_PWM_IRRecord_Receive_Require(MS_U32 u32BufferAddr,MS_U16 u16BufferSize)
2475 {
2476 PM_Result PmResult = E_PM_FAIL;
2477 MBX_Result mbxResult = E_MBX_UNKNOW_ERROR;
2478 MBX_Msg MB_Command;
2479
2480 MS_U32 MBX_Resendcnt = 0;
2481 MS_VIRT virtSrcAddr = 0;
2482
2483 _MDrv_PM_DummyMiuFifo();
2484
2485 PM_DBG_FUNC();
2486 memset((void*)&MB_Command, 0, sizeof(MBX_Msg));
2487 virtSrcAddr = (MS_VIRT)u32BufferAddr;
2488
2489 gPmPWMAckFlags |= E_PM_PWM_ACKFLG_WAIT_IRRECORD_RECIEVE_REQUIRE;
2490
2491 // send to PM51
2492 {
2493 MB_Command.eRoleID = E_MBX_ROLE_PM;
2494 MB_Command.eMsgType = E_MBX_MSG_TYPE_INSTANT;
2495 MB_Command.u8Ctrl = 0; //0x01;
2496 MB_Command.u8MsgClass = E_MBX_CLASS_PM_PWM_NOWAIT;
2497 MB_Command.u8Index = PM_CMDIDX_PWM_IRRECORD_RECEIVED_REQUIRE;
2498 MB_Command.u8ParameterCount = 6;
2499 MB_Command.u8Parameters[0] = (MS_U8)(virtSrcAddr>>24);
2500 MB_Command.u8Parameters[1] = (MS_U8)(virtSrcAddr>>16);
2501 MB_Command.u8Parameters[2] = (MS_U8)(virtSrcAddr>>8);
2502 MB_Command.u8Parameters[3] = (MS_U8)(virtSrcAddr&0x000000FFUL);
2503 MB_Command.u8Parameters[4] = (MS_U8)(u16BufferSize>>8);
2504 MB_Command.u8Parameters[5] = (MS_U8)(u16BufferSize&0x00FFUL);
2505
2506
2507 mbxResult = MDrv_MBX_SendMsg(&MB_Command);
2508
2509 while(E_MBX_SUCCESS != mbxResult)
2510 {
2511 //Error Handling here:
2512 return E_PM_FAIL;
2513 }
2514 }
2515 // Waiting for PM51 Ir Record Recieve Require done
2516 do
2517 {
2518 if(MBX_Resendcnt<10)
2519 {
2520 mbxResult = _MDrv_PM_PWM_MailBoxHandler(&PmResult);
2521 MBX_Resendcnt++;
2522 }
2523 else
2524 {
2525 MBX_Resendcnt=0;
2526 mbxResult = MDrv_MBX_SendMsg(&MB_Command);
2527 while(E_MBX_SUCCESS != mbxResult)
2528 {
2529 //Error Handling here:
2530 return E_PM_FAIL;
2531 }
2532 }
2533 }
2534 while((gPmPWMAckFlags & E_PM_PWM_ACKFLG_WAIT_IRRECORD_RECIEVE_REQUIRE)
2535 &&(mbxResult != E_MBX_ERR_TIME_OUT));
2536
2537 if( E_MBX_SUCCESS != mbxResult)
2538 {
2539 PmResult = E_PM_FAIL;
2540 PM_DBG_ERR("MDrv_PM_PWM_IRRecord_Receive_Require Fail\n");
2541 }
2542 else
2543 {
2544 PmResult = E_PM_OK;
2545 PM_DBG_INFO("MDrv_PM_PWM_IRRecord_Receive_Require OK\n");
2546 }
2547
2548 return PmResult;
2549
2550 }
2551
2552
2553
2554 //-------------------------------------------------------------------------------------------------
2555 /// SN Set PM Recieved IR Pulse Complete and save to file
2556 /// @param u32BufferAddr \b IN: Buffer Address
2557 /// @param u32BuferrSize \b IN: Buffer Size
2558 /// @return @ref PM_Result
2559 //-------------------------------------------------------------------------------------------------
MDrv_PM_PWM_IRRecord_Receive_Complete(MS_U32 u32BufferAddr,MS_U16 u16BufferSize)2560 PM_Result MDrv_PM_PWM_IRRecord_Receive_Complete( MS_U32 u32BufferAddr,MS_U16 u16BufferSize)
2561 {
2562 PM_Result PmResult = E_PM_FAIL;
2563 MBX_Result mbxResult = E_MBX_UNKNOW_ERROR;
2564 MBX_Msg MB_Command;
2565
2566 MS_U32 MBX_Resendcnt = 0;
2567 MS_VIRT virtSrcAddr = 0;
2568
2569 _MDrv_PM_DummyMiuFifo();
2570
2571 PM_DBG_FUNC();
2572 memset((void*)&MB_Command, 0, sizeof(MBX_Msg));
2573 virtSrcAddr = (MS_VIRT)u32BufferAddr;
2574
2575 gPmPWMAckFlags |= E_PM_PWM_ACKFLG_WAIT_IRRECORD_RECIEVE_COMPLETE;
2576
2577 // send to PM51
2578 {
2579 MB_Command.eRoleID = E_MBX_ROLE_PM;
2580 MB_Command.eMsgType = E_MBX_MSG_TYPE_INSTANT;
2581 MB_Command.u8Ctrl = 0; //0x01;
2582 MB_Command.u8MsgClass = E_MBX_CLASS_PM_PWM_NOWAIT;
2583 MB_Command.u8Index = PM_CMDIDX_PWM_IRRECORD_RECEIVED_COMPLETE;
2584 MB_Command.u8ParameterCount = 6;
2585 MB_Command.u8Parameters[0] = (MS_U8)(virtSrcAddr>>24);
2586 MB_Command.u8Parameters[1] = (MS_U8)(virtSrcAddr>>16);
2587 MB_Command.u8Parameters[2] = (MS_U8)(virtSrcAddr>>8);
2588 MB_Command.u8Parameters[3] = (MS_U8)(virtSrcAddr&0x000000FFUL);
2589 MB_Command.u8Parameters[4] = (MS_U8)(u16BufferSize>>8);
2590 MB_Command.u8Parameters[5] = (MS_U8)(u16BufferSize&0x00FFUL);
2591
2592
2593 mbxResult = MDrv_MBX_SendMsg(&MB_Command);
2594
2595 while(E_MBX_SUCCESS != mbxResult)
2596 {
2597 //Error Handling here:
2598 return E_PM_FAIL;
2599 }
2600 }
2601 // Waiting for PM51 Ir Record Recieve complete done
2602 do
2603 {
2604 if(MBX_Resendcnt<10)
2605 {
2606 mbxResult = _MDrv_PM_PWM_MailBoxHandler(&PmResult);
2607 MBX_Resendcnt++;
2608 }
2609 else
2610 {
2611 MBX_Resendcnt=0;
2612 mbxResult = MDrv_MBX_SendMsg(&MB_Command);
2613 while(E_MBX_SUCCESS != mbxResult)
2614 {
2615 //Error Handling here:
2616 return E_PM_FAIL;
2617 }
2618 }
2619 }
2620 while((gPmPWMAckFlags & E_PM_PWM_ACKFLG_WAIT_IRRECORD_RECIEVE_COMPLETE)
2621 &&(mbxResult != E_MBX_ERR_TIME_OUT));
2622
2623 if( E_MBX_SUCCESS != mbxResult)
2624 {
2625 PmResult = E_PM_FAIL;
2626 PM_DBG_ERR("MDrv_PM_PWM_IRRecord_Receive_Complete Fail\n");
2627 }
2628 else
2629 {
2630 PmResult = E_PM_OK;
2631 PM_DBG_INFO("MDrv_PM_PWM_IRRecord_Receive_Complete OK\n");
2632 }
2633
2634 return PmResult;
2635
2636 }
2637
2638 //-------------------------------------------------------------------------------------------------
2639 /// send PM to require for Ir pluse PWM transmit
2640 /// @param u32BufferAddr \b IN: Buffer Address
2641 /// @param u32BuferrSize \b IN: Buffer Size
2642 /// @return @ref PM_Result
2643 //-------------------------------------------------------------------------------------------------
MDrv_PM_PWM_IRRecord_Transmit(MS_U32 u32BufferAddr,MS_U16 u16BufferSize)2644 PM_Result MDrv_PM_PWM_IRRecord_Transmit(MS_U32 u32BufferAddr,MS_U16 u16BufferSize)
2645 {
2646 PM_Result PmResult = E_PM_FAIL;
2647 MBX_Result mbxResult = E_MBX_UNKNOW_ERROR;
2648 MBX_Msg MB_Command;
2649
2650 MS_U32 MBX_Resendcnt = 0;
2651 MS_VIRT virtSrcAddr = 0;
2652
2653 _MDrv_PM_DummyMiuFifo();
2654
2655 PM_DBG_FUNC();
2656 memset((void*)&MB_Command, 0, sizeof(MBX_Msg));
2657 virtSrcAddr = (MS_VIRT)u32BufferAddr;
2658
2659 gPmPWMAckFlags |= E_PM_PWM_ACKFLG_WAIT_IRRECORD_TRANSMIT;
2660
2661 // send to PM51
2662 {
2663 MB_Command.eRoleID = E_MBX_ROLE_PM;
2664 MB_Command.eMsgType = E_MBX_MSG_TYPE_INSTANT;
2665 MB_Command.u8Ctrl = 0; //0x01;
2666 MB_Command.u8MsgClass = E_MBX_CLASS_PM_PWM_NOWAIT;
2667 MB_Command.u8Index = PM_CMDIDX_PWM_IRRECORD_TRANSMIT;
2668 MB_Command.u8ParameterCount = 6;
2669 MB_Command.u8Parameters[0] = (MS_U8)(virtSrcAddr>>24);
2670 MB_Command.u8Parameters[1] = (MS_U8)(virtSrcAddr>>16);
2671 MB_Command.u8Parameters[2] = (MS_U8)(virtSrcAddr>>8);
2672 MB_Command.u8Parameters[3] = (MS_U8)(virtSrcAddr&0x000000FFUL);
2673 MB_Command.u8Parameters[4] = (MS_U8)(u16BufferSize>>8);
2674 MB_Command.u8Parameters[5] = (MS_U8)(u16BufferSize&0x00FFUL);
2675
2676
2677 mbxResult = MDrv_MBX_SendMsg(&MB_Command);
2678
2679 while(E_MBX_SUCCESS != mbxResult)
2680 {
2681 //Error Handling here:
2682 return E_PM_FAIL;
2683 }
2684 }
2685 // Waiting for PM51 Ir Record Transmit done
2686 do
2687 {
2688 if(MBX_Resendcnt<10)
2689 {
2690 mbxResult = _MDrv_PM_PWM_MailBoxHandler(&PmResult);
2691 MBX_Resendcnt++;
2692 }
2693 else
2694 {
2695 MBX_Resendcnt=0;
2696 mbxResult = MDrv_MBX_SendMsg(&MB_Command);
2697 while(E_MBX_SUCCESS != mbxResult)
2698 {
2699 //Error Handling here:
2700 return E_PM_FAIL;
2701 }
2702 }
2703 }
2704 while((gPmPWMAckFlags & E_PM_PWM_ACKFLG_WAIT_IRRECORD_TRANSMIT)
2705 &&(mbxResult != E_MBX_ERR_TIME_OUT));
2706
2707 if( E_MBX_SUCCESS != mbxResult)
2708 {
2709 PmResult = E_PM_FAIL;
2710 PM_DBG_ERR("MDrv_PM_PWM_IRRecord_TRANSMIT Fail\n");
2711 }
2712 else
2713 {
2714 PmResult = E_PM_OK;
2715 PM_DBG_INFO("MDrv_PM_PWM_IRRecord_TRANSMIT OK\n");
2716 }
2717
2718 return PmResult;
2719
2720 }
2721
2722 //-------------------------------------------------------------------------------------------------
2723 /// set IR record call back function
2724 /// @param pCallback \b IN: Ir Record call back funtion
2725 /// @return @ref PM_Result
2726 //-------------------------------------------------------------------------------------------------
MDrv_PM_PWM_IRRecord_SetCallBackFunction(IRRecord_Callback pCallback)2727 PM_Result MDrv_PM_PWM_IRRecord_SetCallBackFunction(IRRecord_Callback pCallback)
2728 {
2729 PM_Result PmResult = E_PM_FAIL;
2730 MBX_Result mbxResult = E_MBX_UNKNOW_ERROR;
2731 MBX_Msg MB_Command;
2732
2733 MS_U32 MBX_Resendcnt = 0;
2734 _MDrv_PM_DummyMiuFifo();
2735
2736 PM_DBG_FUNC();
2737 memset((void*)&MB_Command, 0, sizeof(MBX_Msg));
2738
2739 gfIRRecordCallback = pCallback;
2740 gPmPWMAckFlags |= E_PM_PWM_ACKFLG_WAIT_IRRECORD_SETCALLBACK;
2741
2742 // send to PM51
2743 {
2744 MB_Command.eRoleID = E_MBX_ROLE_PM;
2745 MB_Command.eMsgType = E_MBX_MSG_TYPE_INSTANT;
2746 MB_Command.u8Ctrl = 0; //0x01;
2747 MB_Command.u8MsgClass = E_MBX_CLASS_PM_PWM_NOWAIT;
2748 MB_Command.u8Index = PM_CMDIDX_PWM_IRRECORD_RECEIVED_SETCALLBACK;
2749 MB_Command.u8ParameterCount = 0;
2750 mbxResult = MDrv_MBX_SendMsg(&MB_Command);
2751
2752 while(E_MBX_SUCCESS != mbxResult)
2753 {
2754 //Error Handling here:
2755 return E_PM_FAIL;
2756 }
2757 }
2758 // Waiting for PM51 Ir Record set call back done
2759 do
2760 {
2761 if(MBX_Resendcnt<10)
2762 {
2763 mbxResult = _MDrv_PM_PWM_MailBoxHandler(&PmResult);
2764 MBX_Resendcnt++;
2765 }
2766 else
2767 {
2768 MBX_Resendcnt=0;
2769 mbxResult = MDrv_MBX_SendMsg(&MB_Command);
2770 while(E_MBX_SUCCESS != mbxResult)
2771 {
2772 //Error Handling here:
2773 return E_PM_FAIL;
2774 }
2775 }
2776 }
2777 while((gPmPWMAckFlags & E_PM_PWM_ACKFLG_WAIT_IRRECORD_SETCALLBACK)
2778 &&(mbxResult != E_MBX_ERR_TIME_OUT));
2779
2780 if( E_MBX_SUCCESS != mbxResult)
2781 {
2782 PmResult = E_PM_FAIL;
2783 PM_DBG_ERR("MDrv_PM_PWM_IRRecord_SetCallBackFunction Fail\n");
2784 }
2785 else
2786 {
2787 PmResult = E_PM_OK;
2788 PM_DBG_INFO("MDrv_PM_PWM_IRRecord_SetCallBackFunction OK\n");
2789 }
2790
2791 return PmResult;
2792
2793 }
2794
2795
2796 //-------------------------------------------------------------------------------------------------
2797 /// set IR record Receive Exit
2798 /// @param none
2799 /// @return @ref PM_Result
2800 //-------------------------------------------------------------------------------------------------
MDrv_PM_PWM_IRRecord_Receive_Exit(void)2801 PM_Result MDrv_PM_PWM_IRRecord_Receive_Exit(void)
2802 {
2803 PM_Result PmResult = E_PM_FAIL;
2804 MBX_Result mbxResult = E_MBX_UNKNOW_ERROR;
2805 MBX_Msg MB_Command;
2806
2807 MS_U32 MBX_Resendcnt = 0;
2808 _MDrv_PM_DummyMiuFifo();
2809
2810 PM_DBG_FUNC();
2811 memset((void*)&MB_Command, 0, sizeof(MBX_Msg));
2812
2813 gPmPWMAckFlags |= E_PM_PWM_ACKFLG_WAIT_IRRECORD_RECIEVE_EXIT;
2814
2815 // send to PM51
2816 {
2817 MB_Command.eRoleID = E_MBX_ROLE_PM;
2818 MB_Command.eMsgType = E_MBX_MSG_TYPE_INSTANT;
2819 MB_Command.u8Ctrl = 0; //0x01;
2820 MB_Command.u8MsgClass = E_MBX_CLASS_PM_PWM_NOWAIT;
2821 MB_Command.u8Index = PM_CMDIDX_PWM_IRRECORD_RECEIVED_EXIT;
2822 MB_Command.u8ParameterCount = 0;
2823 mbxResult = MDrv_MBX_SendMsg(&MB_Command);
2824
2825 while(E_MBX_SUCCESS != mbxResult)
2826 {
2827 //Error Handling here:
2828 return E_PM_FAIL;
2829 }
2830 }
2831 // Waiting for PM51 Ir Record RecieveExit done
2832 do
2833 {
2834 if(MBX_Resendcnt<10)
2835 {
2836 mbxResult = _MDrv_PM_PWM_MailBoxHandler(&PmResult);
2837 MBX_Resendcnt++;
2838 }
2839 else
2840 {
2841 MBX_Resendcnt=0;
2842 mbxResult = MDrv_MBX_SendMsg(&MB_Command);
2843 while(E_MBX_SUCCESS != mbxResult)
2844 {
2845 //Error Handling here:
2846 return E_PM_FAIL;
2847 }
2848 }
2849 }
2850 while((gPmPWMAckFlags & E_PM_PWM_ACKFLG_WAIT_IRRECORD_RECIEVE_EXIT)
2851 &&(mbxResult != E_MBX_ERR_TIME_OUT));
2852
2853 if( E_MBX_SUCCESS != mbxResult)
2854 {
2855 PmResult = E_PM_FAIL;
2856 PM_DBG_ERR("MDrv_PM_PWM_IRRecord_Receive_Exit Fail\n");
2857 }
2858 else
2859 {
2860 PmResult = E_PM_OK;
2861 PM_DBG_INFO("MDrv_PM_PWM_IRRecord_Receive_Exit OK\n");
2862 }
2863
2864 return PmResult;
2865
2866 }
2867 ////////////////////////////////////////////////////////////////////////////////
2868 /// @param bTrigger \b In: bTrigger
2869 ////////////////////////////////////////////////////////////////////////////////
MDrv_PM_ActiveStandbyMode(MS_BOOL bTrigger)2870 PM_Result MDrv_PM_ActiveStandbyMode(MS_BOOL bTrigger)
2871 {
2872 MS_VIRT virtBaseAddr;
2873 MS_PHY u32BaseSize;
2874 if(!MDrv_MMIO_GetBASE(&virtBaseAddr, &u32BaseSize,MS_MODULE_PM))
2875 {
2876 PM_DBG_ERR("Get IOMAP Base fail!\n");
2877 return E_PM_FAIL;
2878 }
2879
2880 HAL_PM_SetIOMapBase(virtBaseAddr);
2881 HAL_PM_SetBackGroundTrigger(bTrigger);
2882 return E_PM_OK;
2883 }
2884
2885
2886
2887 ////////////////////////////////////////////////////////////////////////////////
2888 ////////////////////////////////////////////////////////////////////////////////
MDrv_PM_IsActiveStandbyMode(MS_BOOL * bActive)2889 PM_Result MDrv_PM_IsActiveStandbyMode(MS_BOOL *bActive)
2890 {
2891 (*bActive) = FALSE;
2892 MS_VIRT virtBaseAddr;
2893 MS_PHY u32BaseSize;
2894 if(!MDrv_MMIO_GetBASE(&virtBaseAddr, &u32BaseSize,MS_MODULE_PM))
2895 {
2896 PM_DBG_ERR("Get IOMAP Base fail!\n");
2897 return E_PM_FAIL;
2898 }
2899
2900 HAL_PM_SetIOMapBase(virtBaseAddr);
2901 (*bActive) = HAL_PM_GetBackGroundActive();
2902 return E_PM_OK;
2903 }
2904
2905 ////////////////////////////////////////////////////////////////////////////////
2906 /// Set GPIO4 for standby PIN
2907 /// @param bOn \b IN: enable set gpio high ,disable set gpio Low
2908 /// @return @ref PM_Result
2909 ////////////////////////////////////////////////////////////////////////////////
MDrv_PM_GPIO4_SetPower(MS_BOOL bOn)2910 PM_Result MDrv_PM_GPIO4_SetPower(MS_BOOL bOn)
2911 {
2912 MS_VIRT virtBaseAddr=0;
2913 MS_PHY u32BaseSize=0;
2914 if(!MDrv_MMIO_GetBASE(&virtBaseAddr, &u32BaseSize,MS_MODULE_PM))
2915 {
2916 PM_DBG_ERR("Get IOMAP Base fail!\n");
2917 return E_PM_FAIL;
2918 }
2919
2920 HAL_PM_SetIOMapBase(virtBaseAddr);
2921 HAL_PM_GPIO4_SetPower(bOn);
2922 return E_PM_OK;
2923 }
2924
2925 //-------------------------------------------------------------------------------------------------
2926 /// MDrv_PM_RunTimePM_Disable_PassWord
2927 /// @param none
2928 /// @return none
2929 //-------------------------------------------------------------------------------------------------
MDrv_PM_RunTimePM_Disable_PassWord(void)2930 void MDrv_PM_RunTimePM_Disable_PassWord(void)
2931 {
2932 MS_U16 u16Val = 0;
2933 MS_VIRT virtBaseAddr = 0;
2934 MS_PHY u32BaseSize = 0;
2935
2936 if(!MDrv_MMIO_GetBASE(&virtBaseAddr, &u32BaseSize, MS_MODULE_PM))
2937 {
2938 PM_DBG_ERR("%s Get IOMAP Base failed!\n", __FUNCTION__);
2939 return;
2940 }
2941 HAL_PM_SetIOMapBase(virtBaseAddr);
2942 PM_DBG_STR(ULOGD(TAG_PM, "[RT_PM] Start Write PM Run Time PassWord!\n"));
2943 PM_DBG_STR(ULOGD(TAG_PM, "[Send] 0x0EAA = %x\n",HAL_PM_Read2Byte(0x0EAAUL)));
2944 HAL_PM_SetScratchPad(4,0xBABEUL);
2945 PM_DBG_STR(ULOGD(TAG_PM, "[End] 0x0EAA = %x\n",HAL_PM_Read2Byte(0x0EAAUL)));
2946 PM_DBG_STR(ULOGD(TAG_PM, "Wait for PM51 Ideal ...........\n"));
2947 do
2948 {
2949 if(HAL_PM_GetScratchPad(4,&u16Val) == FALSE)
2950 {
2951 continue;
2952 }
2953 }
2954 while(u16Val != 0xAAAAUL);
2955 PM_DBG_STR(ULOGD(TAG_PM, "[RT_PM] End Write PM Run Time PassWord!\n"));
2956 }
2957
2958 //-------------------------------------------------------------------------------------------------
2959 /// MDrv_PM_STR_CheckFactoryPowerOnModePassword
2960 /// @param none
2961 /// @return none
2962 //-------------------------------------------------------------------------------------------------
MDrv_PM_STR_CheckFactoryPowerOnModePassword(void)2963 void MDrv_PM_STR_CheckFactoryPowerOnModePassword(void)
2964 {
2965 PM_DBG_STR(ULOGD(TAG_PM, "[PM] MDrv_PM_STR_CheckFactoryPowerOnMode\n"));
2966 HAL_PM_SetScratchPad(4,0xBBBBUL);
2967 PM_DBG_STR(ULOGD(TAG_PM, "[PM] STR memory factory need AC ON\n"));
2968 }
2969
2970 //-------------------------------------------------------------------------------------------------
2971 /// MDrv_PM_STR_CheckFactoryPowerOnModePassword
2972 /// @param TRUE or FALSE
2973 /// @return none
2974 //-------------------------------------------------------------------------------------------------
MDrv_PM_STR_CheckFactoryPowerOnMode_Second(MS_BOOL bCheck)2975 PM_Result MDrv_PM_STR_CheckFactoryPowerOnMode_Second(MS_BOOL bCheck)
2976 {
2977 MS_U16 u16Val = 0;
2978 MS_BOOL bRet;
2979 if(bCheck)
2980 {
2981 bRet=HAL_PM_GetScratchPad(4,&u16Val);
2982 if((u16Val==0xCCCCUL)||(bRet == FALSE))
2983 return E_PM_FAIL;
2984 else
2985 return E_PM_OK;
2986 }
2987 else
2988 return E_PM_OK;
2989 }
2990
2991
2992 //-------------------------------------------------------------------------------------------------
2993 /// MDrv_PM_STR_CheckFactoryPowerOnModePassword
2994 /// @param TRUE or FALSE
2995 /// @return none
2996 //-------------------------------------------------------------------------------------------------
MDrv_PM_Check_Version(MS_BOOL bCheck)2997 PM_Result MDrv_PM_Check_Version(MS_BOOL bCheck)
2998 {
2999 MS_U8 u8Val = 0;
3000 MS_BOOL bRet;
3001 if(bCheck)
3002 {
3003 bRet=HAL_PM_GetVersion(&u8Val);
3004 if((u8Val==0x20UL)&&(bRet == TRUE))
3005 return E_PM_FAIL;
3006 else
3007 return E_PM_OK;
3008 }
3009 else
3010 return E_PM_OK;
3011 }
3012
MDrv_PM_GetSRAMSize(void)3013 MS_U16 MDrv_PM_GetSRAMSize(void)
3014 {
3015 return HAL_PM_GetSRAMSize();
3016
3017 }
3018
MDrv_PM_GetIRPowerOnKey(void)3019 MS_U8 MDrv_PM_GetIRPowerOnKey(void)
3020 {
3021 return HAL_PM_GetIRPowerOnKey();
3022 }
3023
MDrv_PM_GetRT51Status(void)3024 void MDrv_PM_GetRT51Status(void)
3025 {
3026 HAL_PM_GetRT51Status();
3027 }
3028
3029 #ifdef MSOS_TYPE_LINUX
3030 //-------------------------------------------------------------------------------------------------
3031 ///
3032 /// @param
3033 /// @return
3034 //-------------------------------------------------------------------------------------------------
MDrv_PM_IO_INIT(void)3035 PM_Result MDrv_PM_IO_INIT(void)
3036 {
3037 if (_s32FdPM < 0) //First time open
3038 {
3039 _s32FdPM = open("/dev/pm", O_RDWR);
3040 if (_s32FdPM < 0)
3041 {
3042 return E_PM_FAIL;
3043 }
3044 else
3045 {
3046 return E_PM_OK;
3047 }
3048 }
3049 return E_PM_FAIL;
3050 }
3051
3052 //-------------------------------------------------------------------------------------------------
3053 ///
3054 /// @param
3055 /// @return
3056 //-------------------------------------------------------------------------------------------------
MDrv_PM_WriteDramInfo_Code(MS_U32 u32Addr,MS_U32 u32Size)3057 PM_Result MDrv_PM_WriteDramInfo_Code(MS_U32 u32Addr, MS_U32 u32Size)
3058 {
3059 MS_U32 temp[2];
3060
3061 temp[0] = u32Addr;
3062 temp[1] = u32Size;
3063
3064 if (ioctl(_s32FdPM, IOCTL_PM_SET_DRAM_CODE_ADDRESS, &temp))
3065 {
3066 return E_PM_OK;
3067 }
3068 else
3069 {
3070 return E_PM_FAIL;
3071 }
3072 }
3073
3074 //-------------------------------------------------------------------------------------------------
3075 ///
3076 /// @param
3077 /// @return
3078 //-------------------------------------------------------------------------------------------------
MDrv_PM_WriteDramInfo_Data(MS_U32 u32Addr,MS_U32 u32Size)3079 PM_Result MDrv_PM_WriteDramInfo_Data(MS_U32 u32Addr, MS_U32 u32Size)
3080 {
3081 MS_U32 temp[2];
3082
3083 temp[0] = u32Addr;
3084 temp[1] = u32Size;
3085
3086 if (ioctl(_s32FdPM, IOCTL_PM_SET_DRAM_DATA_ADDRESS, &temp))
3087 {
3088 return E_PM_OK;
3089 }
3090 else
3091 {
3092 return E_PM_FAIL;
3093 }
3094 }
3095 #endif