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 #define _DRVHWI2C_C
94
95 ////////////////////////////////////////////////////////////////////////////////
96 /// file drvHWI2C.c
97 /// @author MStar Semiconductor Inc.
98 /// @brief DRAM byte DMA control driver
99 ////////////////////////////////////////////////////////////////////////////////
100 //------------------------------------------------------------------------------
101 // Header Files
102 //------------------------------------------------------------------------------
103 #if !defined(MSOS_TYPE_LINUX_KERNEL)
104 #include <stdio.h>
105 #include <string.h>
106 #else
107 #include <linux/string.h>
108 #include <linux/slab.h>
109 #endif
110
111 #include "MsCommon.h"
112 #include "MsVersion.h"
113 #include "drvHWI2C.h"
114 #include "halHWI2C.h"
115 #include "drvMMIO.h"
116 #include "MsOS.h"
117 #include "ULog.h"
118
119
120 ////////////////////////////////////////////////////////////////////////////////
121 // Local defines & local structures
122 ////////////////////////////////////////////////////////////////////////////////
123 //define hwi2c ports
124 #ifdef CONFIG_MSTAR_UTPA2K_WDT_ENABLE
125 #define HWI2C_UTOPIA20 (1)
126 #else
127 #define HWI2C_UTOPIA20 (0)
128 #endif
129
130 #ifdef CONFIG_MSTAR_WDT_KERNEL_MODE
131 #define HWI2C_KERNEL_MODE (1)
132 #else
133 #define HWI2C_KERNEL_MODE (0)
134 #endif
135
136 #if (HWI2C_UTOPIA20)
137 #include "utopia.h"
138 #include "drvHWI2C_v2.h"
139 #include "drvHWI2C_private.h"
140 #endif
141
142 #define HWI2C_PORTM 8 //maximum support ports
143 #define HWI2C_PORTS HAL_HWI2C_PORTS
144 #define HWI2C_PORT0 HAL_HWI2C_PORT0
145 #define HWI2C_PORT1 HAL_HWI2C_PORT1
146 #define HWI2C_PORT2 HAL_HWI2C_PORT2
147 #define HWI2C_PORT3 HAL_HWI2C_PORT3
148 #define HWI2C_STARTDLY 5 // 20 //us
149 #define HWI2C_STOPDLY 60 //us
150 //define mutex
151 #define HWI2C_MUTEX_CREATE(_P_) g_s32HWI2CMutex[_P_] = MsOS_CreateMutex(E_MSOS_FIFO, (char*)gu8HWI2CMutexName[_P_] , MSOS_PROCESS_SHARED)
152 #define HWI2C_MUTEX_LOCK(_P_) OS_OBTAIN_MUTEX(g_s32HWI2CMutex[_P_],MSOS_WAIT_FOREVER)
153 #define HWI2C_MUTEX_UNLOCK(_P_) OS_RELEASE_MUTEX(g_s32HWI2CMutex[_P_])
154 #define HWI2C_MUTEX_DELETE(_P_) OS_DELETE_MUTEX(g_s32HWI2CMutex[_P_])
155
156 #define HWI2C_CONTROL_MUTEX_CREATE() g_s32HWI2C_ControlMutex = MsOS_CreateMutex(E_MSOS_FIFO, "HWI2CCONTROLMUTEX" , MSOS_PROCESS_SHARED)
157 #define HWI2C_CONTROL_MUTEX_LOCK() OS_OBTAIN_MUTEX(g_s32HWI2C_ControlMutex,MSOS_WAIT_FOREVER)
158 #define HWI2C_CONTROL_MUTEX_UNLOCK() OS_RELEASE_MUTEX(g_s32HWI2C_ControlMutex)
159 #define HWI2C_CONTROL_MUTEX_DELETE() OS_DELETE_MUTEX(g_s32HWI2C_ControlMutex)
160
161 static MS_U32 g_s32HWI2C_ControlMutex = -1;
162 static MS_S32 g_s32HWI2CMutex[HWI2C_PORTM] = {-1,-1,-1,-1,-1,-1,-1,-1};
163 static char gu8HWI2CMutexName[HWI2C_PORTM][13] = {"HWI2CMUTEXP0","HWI2CMUTEXP1","HWI2CMUTEXP2","HWI2CMUTEXP3","HWI2CMUTEXP4","HWI2CMUTEXP5","HWI2CMUTEXP6","HWI2CMUTEXP7"};
164
165 #define HWI2C_DBG_FUNC() do {if (_geDbgLv >= E_HWI2C_DBGLV_ALL) \
166 {MS_DEBUG_MSG(ULOGI("HWIIC", "\t==== %s ====\n", __FUNCTION__);)} } while(0)
167 #define HWI2C_DBG_INFO(x, args...) do { if (_geDbgLv >= E_HWI2C_DBGLV_INFO ) \
168 {MS_DEBUG_MSG(ULOGI("HWIIC", x, ##args);)} } while(0)
169 #define HWI2C_DBG_ERR(x, args...) do { if (_geDbgLv >= E_HWI2C_DBGLV_ERR_ONLY) \
170 {MS_DEBUG_MSG(ULOGE("HWIIC", x, ##args);)} } while(0)
171
172 #define I2C_ACCESS_DUMMY_TIME 50
173 ////////////////////////////////////////////////////////////////////////////////
174 // Local & Global Variables
175 ////////////////////////////////////////////////////////////////////////////////
176 static MSIF_Version _drv_hwi2c_version = {
177 .DDI = { HWI2C_DRV_VERSION },
178 };
179
180 static MS_BOOL _gbInit = FALSE;
181 static HWI2C_DbgLv _geDbgLv = E_HWI2C_DBGLV_ERR_ONLY;
182 static HWI2C_State _geState = E_HWI2C_IDLE;
183 static HWI2C_State _geStatePortGroup[HWI2C_PORTS];
184 static HWI2C_Info _gsI2CInfo;
185 static MS_U8 g_u8SelectPort = E_HWI2C_PORT_NOSUP;
186 static MS_U32 g_u32StartDelay[HWI2C_PORTS];
187 static MS_U32 g_u32StopDelay[HWI2C_PORTS];
188 static HWI2C_ReadMode g_HWI2CReadMode[HWI2C_PORTS];
189 static HWI2C_PORT g_HWI2CPort[HWI2C_PORTS];
190 static MS_U16 g_u16DelayFactor[HWI2C_PORTS];
191 static MS_BOOL g_bDMAEnable[HWI2C_PORTS];
192 static MS_U8 g_HWI2CPortIdx = HWI2C_PORT0;
193 static HWI2C_UnitCfg g_HWI2CinitCfg;
194 static HWI2C_UnitCfg *gp_HWI2CinitCfg = &g_HWI2CinitCfg;
195
196 #if (HWI2C_UTOPIA20)
197 MS_BOOL bU20HWI2COpened = FALSE;
198 void* pInstantHwi2c;
199 void* pAttributeHwi2c;
200 #endif
201
202 ////////////////////////////////////////////////////////////////////////////////
203 // Local Function
204 ////////////////////////////////////////////////////////////////////////////////
205 #define _MDrv_HWI2C_Send_Byte HAL_HWI2C_Send_Byte
206 #define _MDrv_HWI2C_Recv_Byte HAL_HWI2C_Recv_Byte
207
208 #if 0
209 static void _MDrv_HWI2C_DelayUs(MS_U32 u32Us)
210 {
211 // volatile is necessary to avoid optimization
212 MS_U32 volatile u32Dummy = 0;
213 //MS_U32 u32Loop;
214 MS_U32 volatile u32Loop;
215
216 u32Loop = (MS_U32)(50 * u32Us);
217 while (u32Loop--)
218 {
219 u32Dummy++;
220 }
221 }
222 #endif
223
_MDrv_HWI2C_GetPortRegOffset(MS_U8 u8Port,MS_U32 * pu32Offset)224 static MS_BOOL _MDrv_HWI2C_GetPortRegOffset(MS_U8 u8Port, MS_U32 *pu32Offset)
225 {
226 HWI2C_DBG_FUNC();
227
228 if(u8Port>=HWI2C_PORTS)
229 {
230 HWI2C_DBG_ERR("Port index is >= max supported ports %d !\n",HWI2C_PORTS);
231 return FALSE;
232 }
233 HWI2C_DBG_INFO("g_HWI2CPort[%d] = 0x%02X\n", u8Port, (MS_U8)g_HWI2CPort[u8Port]);
234 return HAL_HWI2C_SetPortRegOffset((HAL_HWI2C_PORT)g_HWI2CPort[u8Port],pu32Offset);
235 }
236
_MDrv_HWI2C_ReadBytes(MS_U8 u8Port,MS_U16 u16SlaveCfg,MS_U32 uAddrCnt,MS_U8 * pRegAddr,MS_U32 uSize,MS_U8 * pData)237 static MS_BOOL _MDrv_HWI2C_ReadBytes(MS_U8 u8Port, MS_U16 u16SlaveCfg, MS_U32 uAddrCnt, MS_U8 *pRegAddr, MS_U32 uSize, MS_U8 *pData)
238 {
239 MS_U8 u8SlaveID = LOW_BYTE(u16SlaveCfg);
240 MS_U32 u32Offset = 0x00;
241 MS_U16 u16Dummy = I2C_ACCESS_DUMMY_TIME; // loop dummy
242 MS_BOOL bComplete = FALSE;
243 MS_U32 uAddrCntBkp,uSizeBkp;
244 MS_U8 *pRegAddrBkp,*pDataBkp;
245
246 HWI2C_DBG_FUNC();
247
248 _geState = E_HWI2C_READ_DATA;
249 _geStatePortGroup[u8Port] = E_HWI2C_READ_DATA;
250 if (!pRegAddr)
251 uAddrCnt = 0;
252 if (!pData)
253 uSize = 0;
254
255 //check support port index
256 if(u8Port>=HWI2C_PORTS)
257 {
258 HWI2C_DBG_ERR("Port index is >= max supported ports %d !\n",HWI2C_PORTS);
259 return FALSE;
260 }
261 //no meaning operation
262 if (!uSize)
263 {
264 HWI2C_DBG_ERR("Read bytes error!\n");
265 return FALSE;
266 }
267
268 //configure port register offset ==> important
269 if(!_MDrv_HWI2C_GetPortRegOffset(u8Port,&u32Offset))
270 {
271 HWI2C_DBG_ERR("Port index error!\n");
272 return FALSE;
273 }
274
275 if(g_bDMAEnable[u8Port])
276 {
277 _geState = E_HWI2C_DMA_READ_DATA;
278 _geStatePortGroup[u8Port] = E_HWI2C_DMA_READ_DATA;
279 return HAL_HWI2C_DMA_ReadBytes(u32Offset, u16SlaveCfg, uAddrCnt, pRegAddr, uSize, pData);
280 }
281
282 //start access routines
283 uAddrCntBkp = uAddrCnt;
284 pRegAddrBkp = pRegAddr;
285 uSizeBkp = uSize;
286 pDataBkp = pData;
287 while (u16Dummy--)
288 {
289 if((g_HWI2CReadMode[u8Port]!=E_HWI2C_READ_MODE_DIRECT) && (uAddrCnt>0)&& (pRegAddr))
290 {
291 HAL_HWI2C_Start(u32Offset);
292 //add extral delay by user configuration
293 MsOS_DelayTaskUs_Poll(g_u32StartDelay[u8Port]);
294
295 if (!_MDrv_HWI2C_Send_Byte(u32Offset,HWI2C_SET_RW_BIT(FALSE, u8SlaveID)))
296 goto end;
297
298 while(uAddrCnt--)
299 {
300 if (!_MDrv_HWI2C_Send_Byte(u32Offset,*pRegAddr))
301 goto end;
302 pRegAddr++;
303 }
304
305 if(g_HWI2CReadMode[u8Port]==E_HWI2C_READ_MODE_DIRECTION_CHANGE_STOP_START)
306 {
307 HAL_HWI2C_Stop(u32Offset);
308 //add extral delay by user configuration
309 MsOS_DelayTaskUs_Poll(g_u32StopDelay[u8Port]);
310 }
311 }
312
313 //Very important to add delay to support all clock speeds
314 //Strongly recommend that do not remove this delay routine
315 HAL_HWI2C_ExtraDelay(g_u16DelayFactor[u8Port]);
316
317 HAL_HWI2C_Start(u32Offset);
318 //add extral delay by user configuration
319 MsOS_DelayTaskUs_Poll(g_u32StartDelay[u8Port]);
320
321 if (!_MDrv_HWI2C_Send_Byte(u32Offset,HWI2C_SET_RW_BIT(TRUE, u8SlaveID)))
322 goto end;
323
324 while(uSize)
325 {
326 ///////////////////////////////////
327 //
328 // must set ACK/NAK before read ready
329 //
330 uSize--;
331 if (uSize==0)
332 HAL_HWI2C_NoAck(u32Offset);
333 if (_MDrv_HWI2C_Recv_Byte(u32Offset,pData)==FALSE)
334 goto end;
335 pData++;
336 }
337 bComplete = TRUE;
338
339 end:
340 HAL_HWI2C_Stop(u32Offset);
341 //add extral delay by user configuration
342 MsOS_DelayTaskUs_Poll(g_u32StopDelay[u8Port]);
343 if(u16Dummy&&(bComplete==FALSE))
344 {
345 uAddrCnt = uAddrCntBkp;
346 pRegAddr = pRegAddrBkp;
347 uSize = uSizeBkp;
348 pData = pDataBkp;
349 continue;
350 }
351 break;
352 }
353 _geState = E_HWI2C_IDLE;
354 _geStatePortGroup[u8Port] = E_HWI2C_IDLE;
355
356 return (uSize) ? FALSE : TRUE;
357 }
358
_MDrv_HWI2C_WriteBytes(MS_U8 u8Port,MS_U16 u16SlaveCfg,MS_U32 uAddrCnt,MS_U8 * pRegAddr,MS_U32 uSize,MS_U8 * pData)359 static MS_BOOL _MDrv_HWI2C_WriteBytes(MS_U8 u8Port, MS_U16 u16SlaveCfg, MS_U32 uAddrCnt, MS_U8 *pRegAddr, MS_U32 uSize, MS_U8 *pData)
360 {
361 MS_U8 u8SlaveID = LOW_BYTE(u16SlaveCfg);
362 MS_U32 u32Offset = 0x00;
363
364 MS_U16 u16Dummy = I2C_ACCESS_DUMMY_TIME; // loop dummy
365 MS_BOOL bComplete = FALSE;
366 MS_U32 uAddrCntBkp,uSizeBkp;
367 MS_U8 *pRegAddrBkp,*pDataBkp;
368
369 HWI2C_DBG_FUNC();
370
371 _geState = E_HWI2C_WRITE_DATA;
372 _geStatePortGroup[u8Port] = E_HWI2C_WRITE_DATA;
373 if (!pRegAddr)
374 uAddrCnt = 0;
375 if (!pData)
376 uSize = 0;
377
378 //check support port index
379 if(u8Port>=HWI2C_PORTS)
380 {
381 HWI2C_DBG_ERR("Port index is >= max supported ports %d !\n",HWI2C_PORTS);
382 return FALSE;
383 }
384 //no meaning operation
385 if (!uSize)
386 {
387 HWI2C_DBG_ERR("Write bytes error!\n");
388 return FALSE;
389 }
390
391 //configure port register offset ==> important
392 if(!_MDrv_HWI2C_GetPortRegOffset(u8Port,&u32Offset))
393 {
394 HWI2C_DBG_ERR("Port index error!\n");
395 return FALSE;
396 }
397
398 if(g_bDMAEnable[u8Port])
399 {
400 _geState = E_HWI2C_DMA_WRITE_DATA;
401 _geStatePortGroup[u8Port] = E_HWI2C_DMA_WRITE_DATA;
402 return HAL_HWI2C_DMA_WriteBytes(u32Offset, u16SlaveCfg, uAddrCnt, pRegAddr, uSize, pData);
403 }
404
405 //start access routines
406 uAddrCntBkp = uAddrCnt;
407 pRegAddrBkp = pRegAddr;
408 uSizeBkp = uSize;
409 pDataBkp = pData;
410 while(u16Dummy--)
411 {
412 HAL_HWI2C_Start(u32Offset);
413 MsOS_DelayTaskUs_Poll(g_u32StartDelay[u8Port]);
414
415 if (!_MDrv_HWI2C_Send_Byte(u32Offset,HWI2C_SET_RW_BIT(FALSE, u8SlaveID)))
416 goto end;
417
418 while(uAddrCnt)
419 {
420 if (!_MDrv_HWI2C_Send_Byte(u32Offset, *pRegAddr))
421 goto end;
422 uAddrCnt--;
423 pRegAddr++;
424 }
425
426 while(uSize)
427 {
428 if (!_MDrv_HWI2C_Send_Byte(u32Offset, *pData))
429 goto end;
430 uSize--;
431 pData++;
432 }
433 bComplete = TRUE;
434
435 end:
436 HAL_HWI2C_Stop(u32Offset);
437 //add extral delay by user configuration
438 MsOS_DelayTaskUs_Poll(g_u32StopDelay[u8Port]);
439 if(u16Dummy&&(bComplete==FALSE))
440 {
441 uAddrCnt = uAddrCntBkp;
442 pRegAddr = pRegAddrBkp;
443 uSize = uSizeBkp;
444 pData = pDataBkp;
445 continue;
446 }
447 break;
448 }
449 _geState = E_HWI2C_IDLE;
450 _geStatePortGroup[u8Port] = E_HWI2C_IDLE;
451
452 return (uSize) ? FALSE : TRUE;
453 }
454
_MDrv_HWI2C_SelectPort(HWI2C_PORT ePort)455 static MS_BOOL _MDrv_HWI2C_SelectPort(HWI2C_PORT ePort)
456 {
457 MS_U32 u32Offset = 0x00;
458 MS_U8 u8Port = 0x00;
459 MS_BOOL bRet=TRUE;
460
461 HWI2C_DBG_FUNC();
462
463 //(1) Get port index by port number
464 if(HAL_HWI2C_GetPortIdxByPort((HAL_HWI2C_PORT)ePort,&u8Port))
465 {
466 g_HWI2CPortIdx = u8Port;
467 g_HWI2CPort[u8Port] = ePort;
468 //set default port parameters
469 g_HWI2CReadMode[u8Port] = E_HWI2C_READ_MODE_DIRECTION_CHANGE;
470 g_u16DelayFactor[u8Port] = 0;
471 #ifdef CONFIG_HWIIC_INTERRUPT_MODE_ENABLE
472 g_bDMAEnable[u8Port] = TRUE;
473 #else
474 g_bDMAEnable[u8Port] = FALSE;
475 #endif
476 }
477 else
478 {
479 g_HWI2CPortIdx = u8Port;
480 //do nothing
481 return FALSE;
482 }
483 HWI2C_DBG_INFO("ePort:0x%02X, u8Port:0x%02X\n",(MS_U8)ePort, u8Port);
484
485 //(2) Set pad mux for port number
486 HAL_HWI2C_SelectPort((HAL_HWI2C_PORT)ePort);
487
488 //(3) configure port register offset ==> important
489 bRet &= _MDrv_HWI2C_GetPortRegOffset(u8Port,&u32Offset);
490
491 //(4) master init
492 bRet &= HAL_HWI2C_Master_Enable(u32Offset);
493
494 return bRet;
495 }
496
_MDrv_HWI2C_SetClk(MS_U8 u8Port,HWI2C_CLKSEL eClk)497 static MS_BOOL _MDrv_HWI2C_SetClk(MS_U8 u8Port, HWI2C_CLKSEL eClk)
498 {
499 MS_U32 u32Offset = 0x00;
500
501 HWI2C_DBG_FUNC();
502 HWI2C_DBG_INFO("Port%d clk: %u\n", u8Port, eClk);
503 //check support port index
504 if(u8Port>=HWI2C_PORTS)
505 {
506 HWI2C_DBG_ERR("Port index is >= max supported ports %d !\n",HWI2C_PORTS);
507 return FALSE;
508 }
509 //check support clock speed
510 if (eClk >= E_HWI2C_NOSUP)
511 {
512 HWI2C_DBG_ERR("Clock [%u] is not supported!\n",eClk);
513 return FALSE;
514 }
515
516 //configure port register offset ==> important
517 if(!_MDrv_HWI2C_GetPortRegOffset(u8Port,&u32Offset))
518 {
519 HWI2C_DBG_ERR("Port index error!\n");
520 return FALSE;
521 }
522
523 g_u16DelayFactor[u8Port] = (MS_U16)(1<<(eClk));
524 return HAL_HWI2C_SetClk(u32Offset,(HAL_HWI2C_CLKSEL)eClk);
525 }
526
_MDrv_HWI2C_SetReadMode(MS_U8 u8Port,HWI2C_ReadMode eReadMode)527 static MS_BOOL _MDrv_HWI2C_SetReadMode(MS_U8 u8Port, HWI2C_ReadMode eReadMode)
528 {
529 HWI2C_DBG_FUNC();
530 HWI2C_DBG_INFO("Port%d Readmode: %u\n", u8Port, eReadMode);
531 //check support port index
532 if(u8Port>=HWI2C_PORTS)
533 {
534 HWI2C_DBG_ERR("Port index is >= max supported ports %d !\n",HWI2C_PORTS);
535 return FALSE;
536 }
537 if(eReadMode>=E_HWI2C_READ_MODE_MAX)
538 return FALSE;
539 g_HWI2CReadMode[u8Port] = eReadMode;
540 return TRUE;
541 }
542
_MDrv_HWI2C_InitPort(HWI2C_UnitCfg * psCfg)543 static MS_BOOL _MDrv_HWI2C_InitPort(HWI2C_UnitCfg *psCfg)
544 {
545 MS_U8 u8PortIdx = 0, u8Port = 0;
546 MS_U32 u32Offset = 0x00;
547 MS_BOOL bRet = TRUE;
548 HWI2C_PortCfg stPortCfg;
549
550 HWI2C_DBG_FUNC();
551
552 //(1) set default value for port variables
553 for(u8PortIdx=0; u8PortIdx < HWI2C_PORTS; u8PortIdx++)
554 {
555 stPortCfg = psCfg->sCfgPort[u8PortIdx];
556 if(stPortCfg.bEnable)
557 {
558 if(_MDrv_HWI2C_SelectPort(stPortCfg.ePort))
559 {
560 //set clock speed
561 bRet &= _MDrv_HWI2C_SetClk(g_HWI2CPortIdx, stPortCfg.eSpeed);
562 //set read mode
563 bRet &= _MDrv_HWI2C_SetReadMode(g_HWI2CPortIdx, stPortCfg.eReadMode);
564 //get port index
565 bRet &= HAL_HWI2C_GetPortIdxByPort((HAL_HWI2C_PORT)stPortCfg.ePort,&u8Port);
566 //configure port register offset ==> important
567 bRet &= _MDrv_HWI2C_GetPortRegOffset(u8Port,&u32Offset);
568 //master init
569 bRet &= HAL_HWI2C_Master_Enable(u32Offset);
570 //dma init
571 bRet &= HAL_HWI2C_DMA_Init(u32Offset,(HAL_HWI2C_PortCfg*)&stPortCfg);
572 g_bDMAEnable[u8Port] = stPortCfg.bDmaEnable;
573 //dump port information
574 HWI2C_DBG_INFO("Port:%u Index=%u\n",stPortCfg.ePort,u8Port);
575 HWI2C_DBG_INFO("Enable=%u\n",stPortCfg.bEnable);
576 HWI2C_DBG_INFO("DmaReadMode:%u\n",stPortCfg.eReadMode);
577 HWI2C_DBG_INFO("Speed:%u\n",stPortCfg.eSpeed);
578 HWI2C_DBG_INFO("DmaEnable:%u\n",stPortCfg.bDmaEnable);
579 HWI2C_DBG_INFO("DmaAddrMode:%u\n",stPortCfg.eDmaAddrMode);
580 HWI2C_DBG_INFO("DmaMiuCh:%u\n",stPortCfg.eDmaMiuCh);
581 HWI2C_DBG_INFO("DmaMiuPri:%u\n",stPortCfg.eDmaMiuPri);
582 HWI2C_DBG_INFO("DmaPhyAddr:%lx\n",stPortCfg.u32DmaPhyAddr);
583 }
584 }
585 }
586
587 //(2) check initialized port : override above port configuration
588 if(_MDrv_HWI2C_SelectPort(psCfg->ePort))
589 {
590 //set clock speed
591 bRet &=_MDrv_HWI2C_SetClk(g_HWI2CPortIdx,psCfg->eSpeed);
592 //set read mode
593 bRet &=_MDrv_HWI2C_SetReadMode(g_HWI2CPortIdx,psCfg->eReadMode);
594 //get port index
595 bRet &= HAL_HWI2C_GetPortIdxByPort((HAL_HWI2C_PORT)psCfg->ePort,&u8Port);
596 //configure port register offset ==> important
597 bRet &= _MDrv_HWI2C_GetPortRegOffset(u8Port,&u32Offset);
598 //master init
599 bRet &= HAL_HWI2C_Master_Enable(u32Offset);
600 }
601
602 //(3) dump allocated port information
603 for(u8PortIdx=0; u8PortIdx < HWI2C_PORTS; u8PortIdx++)
604 {
605 HWI2C_DBG_INFO("HWI2C Allocated Port[%d] = 0x%02X\n",u8PortIdx,g_HWI2CPort[u8PortIdx]);
606 }
607
608 return bRet;
609 }
610
611 ////////////////////////////////////////////////////////////////////////////////
612 // Global Functions
613 ////////////////////////////////////////////////////////////////////////////////
614
615 ////////////////////////////////////////////////////////////////////////////////
616 /// @brief \b Function \b Name: MDrv_HWI2C_Init
617 /// @brief \b Function \b Description: Init HWI2C driver
618 /// @param psCfg \b IN: hw I2C config
619 /// @return \b TRUE: Success FALSE: Fail
620 ////////////////////////////////////////////////////////////////////////////////
MDrv_HWI2C_Init_U2K(HWI2C_UnitCfg * psCfg)621 MS_BOOL MDrv_HWI2C_Init_U2K(HWI2C_UnitCfg *psCfg)
622 {
623 MS_BOOL bRet = TRUE;
624 MS_VIRT u32BaseAddr = 0xFFFFFFFFUL;
625 MS_PHY u32BaseSize;
626 MS_U8 u8Port=0;
627
628 HWI2C_DBG_FUNC();
629
630 if (psCfg == NULL)
631 return FALSE;
632
633 //store psCfg for FastBoot resume
634 gp_HWI2CinitCfg = &g_HWI2CinitCfg;
635 gp_HWI2CinitCfg->eReadMode = psCfg->eReadMode;
636 gp_HWI2CinitCfg->ePort = psCfg->ePort;
637 gp_HWI2CinitCfg->eSpeed = psCfg->eSpeed;
638 gp_HWI2CinitCfg->sI2CPin = psCfg->sI2CPin;
639 gp_HWI2CinitCfg->sCfgPort[0] = psCfg->sCfgPort[0];
640 gp_HWI2CinitCfg->sCfgPort[1] = psCfg->sCfgPort[1];
641 gp_HWI2CinitCfg->sCfgPort[2] = psCfg->sCfgPort[2];
642 gp_HWI2CinitCfg->sCfgPort[3] = psCfg->sCfgPort[3];
643 if (_gbInit)
644 {
645 HWI2C_DBG_INFO("HW I2C has been initialed!\n");
646 return TRUE;
647 }
648 //(1) get & set io base
649 if ((!psCfg) || (!MDrv_MMIO_GetBASE(&u32BaseAddr, &u32BaseSize, MS_MODULE_HWI2C)))
650 return FALSE;
651 HAL_HWI2C_SetIOMapBase(u32BaseAddr);
652
653 //(2) Initialize pad mux and basic settings
654 HWI2C_DBG_INFO("Pinreg:%lx bit:%u enable:%u speed:%u\n",psCfg->sI2CPin.u32Reg, psCfg->sI2CPin.u8BitPos, psCfg->sI2CPin.bEnable,psCfg->eSpeed);
655 bRet &= HAL_HWI2C_Init_Chip();
656 //(3) Initialize all port
657 bRet &= _MDrv_HWI2C_InitPort(psCfg);
658 //(4) Check final result
659 if (!bRet)
660 {
661 HWI2C_DBG_ERR("I2C init fail!\n");
662 }
663
664 //(5) Extra procedure to do after initialization
665 HAL_HWI2C_Init_ExtraProc();
666
667 _gsI2CInfo.u32IOMap = u32BaseAddr;
668 for(u8Port=0;u8Port<(MS_U8)HWI2C_PORTS;u8Port++)
669 {
670 _geStatePortGroup[u8Port] = E_HWI2C_IDLE;
671 g_u32StartDelay[u8Port] = HWI2C_STARTDLY;
672 g_u32StopDelay[u8Port] = HWI2C_STOPDLY;
673 HWI2C_DBG_INFO("Port:%d, START default delay %d(us)\n",u8Port, (int)g_u32StartDelay[u8Port]);
674 HWI2C_DBG_INFO("Port:%d, STOP default delay %d(us)\n",u8Port, (int)g_u32StopDelay[u8Port]);
675 }
676 memcpy(&_gsI2CInfo.sUnitCfg, psCfg, sizeof(HWI2C_UnitCfg));
677 _gbInit = TRUE;
678
679 HWI2C_DBG_INFO("HWI2C_MUTEX_CREATE!\n");
680 for(u8Port=0;u8Port<(MS_U8)HWI2C_PORTS;u8Port++)
681 {
682 HWI2C_MUTEX_CREATE(u8Port);
683 }
684 HWI2C_CONTROL_MUTEX_CREATE();
685
686 return bRet;
687 }
688
689 ////////////////////////////////////////////////////////////////////////////////
690 /// @brief \b Function \b Name: MDrv_HWI2C_Start
691 /// @brief \b Function \b Description: send start bit
692 /// @return \b TRUE: Success FALSE: Fail
693 ////////////////////////////////////////////////////////////////////////////////
MDrv_HWI2C_Start_U2K(void)694 MS_BOOL MDrv_HWI2C_Start_U2K(void)
695 {
696 HWI2C_DBG_FUNC();
697 return HAL_HWI2C_Start(0x0000);
698 }
699
700 ////////////////////////////////////////////////////////////////////////////////
701 /// @brief \b Function \b Name: MDrv_HWI2C_Stop
702 /// @brief \b Function \b Description: send stop bit
703 /// @return \b TRUE: Success FALSE: Fail
704 ////////////////////////////////////////////////////////////////////////////////
MDrv_HWI2C_Stop_U2K(void)705 MS_BOOL MDrv_HWI2C_Stop_U2K(void)
706 {
707 HWI2C_DBG_FUNC();
708 return HAL_HWI2C_Stop(0x0000);
709 }
710
711 ////////////////////////////////////////////////////////////////////////////////
712 /// @brief \b Function \b Name: MDrv_HWI2C_GetPortIndex
713 /// @brief \b Function \b Description: Get port index from port number
714 /// @param ePort \b IN: port number
715 /// @param ePort \b OUT: pointer to port index
716 /// @return \b MS_U8: Port Index
717 ////////////////////////////////////////////////////////////////////////////////
MDrv_HWI2C_GetPortIndex(HWI2C_PORT ePort,MS_U8 * pu8Port)718 MS_BOOL MDrv_HWI2C_GetPortIndex(HWI2C_PORT ePort, MS_U8* pu8Port)
719 {
720 MS_BOOL bRet=TRUE;
721
722 HWI2C_DBG_FUNC();
723
724 //(1) Get port index by port number
725 bRet &= HAL_HWI2C_GetPortIdxByPort((HAL_HWI2C_PORT)ePort, pu8Port);
726 HWI2C_DBG_INFO("ePort:0x%02X, u8Port:0x%02X\n",(MS_U8)ePort,(MS_U8)*pu8Port);
727
728 return bRet;
729 }
730
731 //###################
732 //
733 // Multi-Port Support: Port 0
734 //
735 //###################
736 ////////////////////////////////////////////////////////////////////////////////
737 /// @brief \b Function \b Name: MDrv_HWI2C_SelectPort
738 /// @brief \b Function \b Description: Decide port index and pad mux for port number
739 /// @param ePort \b IN: port number
740 /// @return \b TRUE: Success FALSE: Fail
741 ////////////////////////////////////////////////////////////////////////////////
MDrv_HWI2C_SelectPort_U2K(HWI2C_PORT ePort)742 MS_BOOL MDrv_HWI2C_SelectPort_U2K(HWI2C_PORT ePort)
743 {
744 MS_BOOL bRet;
745 HWI2C_DBG_FUNC();
746 if(ePort >= E_HWI2C_PORT_NOSUP)
747 return FALSE;
748 HWI2C_CONTROL_MUTEX_LOCK();
749 bRet = _MDrv_HWI2C_SelectPort(ePort);
750 if (bRet == TRUE)
751 g_u8SelectPort = ePort;
752 HWI2C_CONTROL_MUTEX_UNLOCK();
753 return bRet;
754 }
755
756 ////////////////////////////////////////////////////////////////////////////////
757 /// @brief \b Function \b Name: MDrv_HWI2C_SetClk
758 /// @brief \b Function \b Description: Set HW I2C clock
759 /// @param eClk \b IN: clock rate
760 /// @return \b TRUE: Success FALSE: Fail
761 ////////////////////////////////////////////////////////////////////////////////
MDrv_HWI2C_SetClk_U2K(HWI2C_CLKSEL eClk)762 MS_BOOL MDrv_HWI2C_SetClk_U2K(HWI2C_CLKSEL eClk)
763 {
764 HWI2C_DBG_FUNC();
765 return _MDrv_HWI2C_SetClk(g_HWI2CPortIdx, eClk);
766 }
767
768 ////////////////////////////////////////////////////////////////////////////////
769 /// @brief \b Function \b Name: MDrv_HWI2C_SetReadMode
770 /// @brief \b Function \b Description: Set HW I2C Read Mode
771 /// @param eClk \b IN: ReadMode
772 /// @return \b TRUE: Success FALSE: Fail
773 ////////////////////////////////////////////////////////////////////////////////
MDrv_HWI2C_SetReadMode(HWI2C_ReadMode eReadMode)774 MS_BOOL MDrv_HWI2C_SetReadMode(HWI2C_ReadMode eReadMode)
775 {
776 return _MDrv_HWI2C_SetReadMode(g_HWI2CPortIdx, eReadMode);
777 }
778
779 ////////////////////////////////////////////////////////////////////////////////
780 /// @brief \b Function \b Name: MDrv_HWI2C_ReadByte
781 /// @brief \b Function \b Description: read 1 byte data
782 /// @param u16SlaveCfg \b IN: [15:8]: Channel number [7:0]:Slave ID
783 /// @param u8RegAddr \b IN: target register address
784 /// @param pData \b Out: read 1 byte data
785 /// @return \b TRUE: Success FALSE: Fail
786 ////////////////////////////////////////////////////////////////////////////////
MDrv_HWI2C_ReadByte(MS_U16 u16SlaveCfg,MS_U8 u8RegAddr,MS_U8 * pData)787 MS_BOOL MDrv_HWI2C_ReadByte(MS_U16 u16SlaveCfg, MS_U8 u8RegAddr, MS_U8 *pData)
788 {
789 HWI2C_DBG_FUNC();
790 return MDrv_HWI2C_ReadBytes(u16SlaveCfg, 1, &u8RegAddr, 1, pData);
791 }
792
793 ////////////////////////////////////////////////////////////////////////////////
794 /// @brief \b Function \b Name: MDrv_HWI2C_ReadByte
795 /// @brief \b Function \b Description: write 1 byte data
796 /// @param u16SlaveCfg \b IN: [15:8]: Channel number [7:0]:Slave ID
797 /// @param u8RegAddr \b IN: target register address
798 /// @param u8Data \b IN: 1 byte data
799 /// @return \b TRUE: Success FALSE: Fail
800 ////////////////////////////////////////////////////////////////////////////////
MDrv_HWI2C_WriteByte(MS_U16 u16SlaveCfg,MS_U8 u8RegAddr,MS_U8 u8Data)801 MS_BOOL MDrv_HWI2C_WriteByte(MS_U16 u16SlaveCfg, MS_U8 u8RegAddr, MS_U8 u8Data)
802 {
803 HWI2C_DBG_FUNC();
804 return MDrv_HWI2C_WriteBytes_U2K(u16SlaveCfg, 1, &u8RegAddr, 1, &u8Data);
805 }
806
807 ////////////////////////////////////////////////////////////////////////////////
808 /// @brief \b Function \b Name: MDrv_HWI2C_WriteBytes
809 /// @brief \b Function \b Description: Init HWI2C driver
810 /// @param u16SlaveCfg \b IN: [15:8]: Channel number [7:0]:Slave ID
811 /// @param uAddrCnt \b IN: register address count
812 /// @param pRegAddr \b IN: pointer to targert register address
813 /// @param uSize \b IN: data length
814 /// @param pData \b IN: data array
815 /// @return \b TRUE: Success FALSE: Fail
816 ////////////////////////////////////////////////////////////////////////////////
MDrv_HWI2C_WriteBytes_U2K(MS_U16 u16SlaveCfg,MS_U32 uAddrCnt,MS_U8 * pRegAddr,MS_U32 uSize,MS_U8 * pData)817 MS_BOOL MDrv_HWI2C_WriteBytes_U2K(MS_U16 u16SlaveCfg, MS_U32 uAddrCnt, MS_U8 *pRegAddr, MS_U32 uSize, MS_U8 *pData)
818 {
819 MS_BOOL bRet;
820 MS_U8 u8Port;
821
822 u8Port = HIGH_BYTE(u16SlaveCfg);
823 if(u8Port>=HWI2C_PORTS)
824 {
825 HWI2C_DBG_ERR("Port index is >= max supported ports %d !\n",HWI2C_PORTS);
826 return FALSE;
827 }
828 HWI2C_MUTEX_LOCK(u8Port);
829 bRet = _MDrv_HWI2C_WriteBytes(u8Port,u16SlaveCfg,uAddrCnt,pRegAddr,uSize,pData);
830 HWI2C_MUTEX_UNLOCK(u8Port);
831 return bRet;
832 }
833
834 ////////////////////////////////////////////////////////////////////////////////
835 /// @brief \b Function \b Name: MDrv_HWI2C_ReadBytes
836 /// @brief \b Function \b Description: Init HWI2C driver
837 /// @param u16SlaveCfg \b IN: [15:8]: Channel number [7:0]:Slave ID
838 /// @param uAddrCnt \b IN: register address count
839 /// @param pRegAddr \b IN: pointer to targert register address
840 /// @param uSize \b IN: data length
841 /// @param pData \b Out: read data aray
842 /// @return \b TRUE: Success FALSE: Fail
843 ////////////////////////////////////////////////////////////////////////////////
MDrv_HWI2C_ReadBytes_U2K(MS_U16 u16SlaveCfg,MS_U32 uAddrCnt,MS_U8 * pRegAddr,MS_U32 uSize,MS_U8 * pData)844 MS_BOOL MDrv_HWI2C_ReadBytes_U2K(MS_U16 u16SlaveCfg, MS_U32 uAddrCnt, MS_U8 *pRegAddr, MS_U32 uSize, MS_U8 *pData)
845 {
846 MS_BOOL bRet;
847 MS_U8 u8Port;
848
849 u8Port = HIGH_BYTE(u16SlaveCfg);
850 if(u8Port>=HWI2C_PORTS)
851 {
852 HWI2C_DBG_ERR("Port index is >= max supported ports %d !\n",HWI2C_PORTS);
853 return FALSE;
854 }
855 HWI2C_MUTEX_LOCK(u8Port);
856 bRet = _MDrv_HWI2C_ReadBytes(u8Port,u16SlaveCfg,uAddrCnt,pRegAddr,uSize,pData);
857 HWI2C_MUTEX_UNLOCK(u8Port);
858 return bRet;
859 }
860
861 //###################
862 //
863 // Multi-Port Support: Port 1
864 //
865 //###################
866 ////////////////////////////////////////////////////////////////////////////////
867 /// @brief \b Function \b Name: MDrv_HWI2C_SelectPort1
868 /// @brief \b Function \b Description: Decide port index and pad mux for port number
869 /// @param ePort \b IN: port number
870 /// @return \b TRUE: Success FALSE: Fail
871 ////////////////////////////////////////////////////////////////////////////////
MDrv_HWI2C_SelectPort1(HWI2C_PORT ePort)872 MS_BOOL MDrv_HWI2C_SelectPort1(HWI2C_PORT ePort)
873 {
874 MS_BOOL bRet;
875 HWI2C_DBG_FUNC();
876 if(ePort >= E_HWI2C_PORT_NOSUP)
877 return FALSE;
878 HWI2C_CONTROL_MUTEX_LOCK();
879 bRet = _MDrv_HWI2C_SelectPort(ePort);
880 if (bRet == TRUE)
881 g_u8SelectPort = ePort;
882 HWI2C_CONTROL_MUTEX_UNLOCK();
883 return bRet;
884 }
885
886 ////////////////////////////////////////////////////////////////////////////////
887 /// @brief \b Function \b Name: MDrv_HWI2C_SetClkP1
888 /// @brief \b Function \b Description: Set HW I2C clock
889 /// @param eClk \b IN: clock rate
890 /// @return \b TRUE: Success FALSE: Fail
891 ////////////////////////////////////////////////////////////////////////////////
MDrv_HWI2C_SetClkP1(HWI2C_CLKSEL eClk)892 MS_BOOL MDrv_HWI2C_SetClkP1(HWI2C_CLKSEL eClk)
893 {
894 HWI2C_DBG_FUNC();
895 return _MDrv_HWI2C_SetClk(HWI2C_PORT1, eClk);
896 }
897
898 ////////////////////////////////////////////////////////////////////////////////
899 /// @brief \b Function \b Name: MDrv_HWI2C_SetReadModeP1
900 /// @brief \b Function \b Description: Set HW I2C Read Mode
901 /// @param eClk \b IN: ReadMode
902 /// @return \b TRUE: Success FALSE: Fail
903 ////////////////////////////////////////////////////////////////////////////////
MDrv_HWI2C_SetReadModeP1(HWI2C_ReadMode eReadMode)904 MS_BOOL MDrv_HWI2C_SetReadModeP1(HWI2C_ReadMode eReadMode)
905 {
906 return _MDrv_HWI2C_SetReadMode(HWI2C_PORT1, eReadMode);
907 }
908
909 ////////////////////////////////////////////////////////////////////////////////
910 /// @brief \b Function \b Name: MDrv_HWI2C_ReadByteP1
911 /// @brief \b Function \b Description: read 1 byte data
912 /// @param u16SlaveCfg \b IN: [15:8]: Channel number [7:0]:Slave ID
913 /// @param u8RegAddr \b IN: target register address
914 /// @param pData \b Out: read 1 byte data
915 /// @return \b TRUE: Success FALSE: Fail
916 ////////////////////////////////////////////////////////////////////////////////
MDrv_HWI2C_ReadByteP1(MS_U16 u16SlaveCfg,MS_U8 u8RegAddr,MS_U8 * pData)917 MS_BOOL MDrv_HWI2C_ReadByteP1(MS_U16 u16SlaveCfg, MS_U8 u8RegAddr, MS_U8 *pData)
918 {
919 HWI2C_DBG_FUNC();
920 return MDrv_HWI2C_ReadBytesP1(u16SlaveCfg, 1, &u8RegAddr, 1, pData);
921 }
922
923 ////////////////////////////////////////////////////////////////////////////////
924 /// @brief \b Function \b Name: MDrv_HWI2C_ReadByteP1
925 /// @brief \b Function \b Description: write 1 byte data
926 /// @param u16SlaveCfg \b IN: [15:8]: Channel number [7:0]:Slave ID
927 /// @param u8RegAddr \b IN: target register address
928 /// @param u8Data \b IN: 1 byte data
929 /// @return \b TRUE: Success FALSE: Fail
930 ////////////////////////////////////////////////////////////////////////////////
MDrv_HWI2C_WriteByteP1(MS_U16 u16SlaveCfg,MS_U8 u8RegAddr,MS_U8 u8Data)931 MS_BOOL MDrv_HWI2C_WriteByteP1(MS_U16 u16SlaveCfg, MS_U8 u8RegAddr, MS_U8 u8Data)
932 {
933 HWI2C_DBG_FUNC();
934 return MDrv_HWI2C_WriteBytesP1(u16SlaveCfg, 1, &u8RegAddr, 1, &u8Data);
935 }
936
937 ////////////////////////////////////////////////////////////////////////////////
938 /// @brief \b Function \b Name: MDrv_HWI2C_WriteBytesP1
939 /// @brief \b Function \b Description: Init HWI2C driver
940 /// @param u16SlaveCfg \b IN: [15:8]: Channel number [7:0]:Slave ID
941 /// @param uAddrCnt \b IN: register address count
942 /// @param pRegAddr \b IN: pointer to targert register address
943 /// @param uSize \b IN: data length
944 /// @param pData \b IN: data array
945 /// @return \b TRUE: Success FALSE: Fail
946 ////////////////////////////////////////////////////////////////////////////////
MDrv_HWI2C_WriteBytesP1(MS_U16 u16SlaveCfg,MS_U32 uAddrCnt,MS_U8 * pRegAddr,MS_U32 uSize,MS_U8 * pData)947 MS_BOOL MDrv_HWI2C_WriteBytesP1(MS_U16 u16SlaveCfg, MS_U32 uAddrCnt, MS_U8 *pRegAddr, MS_U32 uSize, MS_U8 *pData)
948 {
949 MS_BOOL bRet;
950
951 HWI2C_MUTEX_LOCK(HWI2C_PORT1);
952 bRet = _MDrv_HWI2C_WriteBytes(HWI2C_PORT1,u16SlaveCfg,uAddrCnt,pRegAddr,uSize,pData);
953 HWI2C_MUTEX_UNLOCK(HWI2C_PORT1);
954 return bRet;
955 }
956
957 ////////////////////////////////////////////////////////////////////////////////
958 /// @brief \b Function \b Name: MDrv_HWI2C_ReadBytesP1
959 /// @brief \b Function \b Description: Init HWI2C driver
960 /// @param u16SlaveCfg \b IN: [15:8]: Channel number [7:0]:Slave ID
961 /// @param uAddrCnt \b IN: register address count
962 /// @param pRegAddr \b IN: pointer to targert register address
963 /// @param uSize \b IN: data length
964 /// @param pData \b Out: read data aray
965 /// @return \b TRUE: Success FALSE: Fail
966 ////////////////////////////////////////////////////////////////////////////////
MDrv_HWI2C_ReadBytesP1(MS_U16 u16SlaveCfg,MS_U32 uAddrCnt,MS_U8 * pRegAddr,MS_U32 uSize,MS_U8 * pData)967 MS_BOOL MDrv_HWI2C_ReadBytesP1(MS_U16 u16SlaveCfg, MS_U32 uAddrCnt, MS_U8 *pRegAddr, MS_U32 uSize, MS_U8 *pData)
968 {
969 MS_BOOL bRet;
970
971 HWI2C_MUTEX_LOCK(HWI2C_PORT1);
972 bRet = _MDrv_HWI2C_ReadBytes(HWI2C_PORT1,u16SlaveCfg,uAddrCnt,pRegAddr,uSize,pData);
973 HWI2C_MUTEX_UNLOCK(HWI2C_PORT1);
974 return bRet;
975 }
976
977 ////////////////////////////////////////////////////////////////////////////////
978 /// @brief \b Function \b Name: MDrv_HWI2C_SetDbgLevel
979 /// @brief \b Function \b Description: Set debug level for debug message
980 /// @param eLevel \b IN: E_HWI2C_DBGLV_NONE/E_HWI2C_DBGLV_ERR_ONLY/E_HWI2C_DBGLV_INFO/E_HWI2C_DBGLV_ALL
981 /// @return \b TRUE: Success FALSE: Fail
982 ////////////////////////////////////////////////////////////////////////////////
MDrv_HWI2C_SetDbgLevel(HWI2C_DbgLv eLevel)983 MS_BOOL MDrv_HWI2C_SetDbgLevel(HWI2C_DbgLv eLevel)
984 {
985 HWI2C_DBG_FUNC();
986 HWI2C_DBG_INFO("level: %u\n", eLevel);
987 _geDbgLv = eLevel;
988 return TRUE;
989 }
990
991 ////////////////////////////////////////////////////////////////////////////////
992 /// @brief \b Function \b Name: MDrv_HWI2C_GetLibVer
993 /// @brief \b Function \b Description: Show the HW I2C driver version
994 /// @param ppVersion \b Out: output HW I2C driver version
995 /// @return \b TRUE: Success FALSE: Fail
996 ////////////////////////////////////////////////////////////////////////////////
MDrv_HWI2C_GetLibVer(const MSIF_Version ** ppVersion)997 MS_BOOL MDrv_HWI2C_GetLibVer(const MSIF_Version **ppVersion)
998 {
999 HWI2C_DBG_FUNC();
1000 if (!ppVersion)
1001 return FALSE;
1002 *ppVersion = &_drv_hwi2c_version;
1003 return TRUE;
1004 }
1005
1006 ////////////////////////////////////////////////////////////////////////////////
1007 /// @brief \b Function \b Name: MDrv_HWI2C_GetStatus
1008 /// @brief \b Function \b Description: Get HW I2C driver status
1009 /// @param pStatus \b Out : Hw I2C driver status
1010 ////////////////////////////////////////////////////////////////////////////////
MDrv_HWI2C_GetStatus(HWI2C_Status * pStatus)1011 void MDrv_HWI2C_GetStatus(HWI2C_Status *pStatus)
1012 {
1013 MS_U8 u8Port;
1014 MS_BOOL bFlag = TRUE;
1015 HWI2C_DBG_FUNC();
1016 if (!pStatus)
1017 return;
1018
1019 HWI2C_CONTROL_MUTEX_LOCK();
1020 u8Port =(MS_U8) g_u8SelectPort / 8;
1021
1022 if (u8Port >= HWI2C_PORTS)
1023 bFlag = FALSE;
1024 pStatus->bIsInit = _gbInit;
1025 pStatus->u8DbgLevel = _geDbgLv;
1026 pStatus->bIsMaster = HAL_HWI2C_IsMaster();
1027 pStatus->eState =(bFlag == TRUE? _geStatePortGroup[u8Port] : _geState);
1028 HWI2C_CONTROL_MUTEX_UNLOCK();
1029 }
1030
MDrv_HWI2C_GetStatus_EX(void * pParam_Status)1031 void MDrv_HWI2C_GetStatus_EX(void *pParam_Status)
1032 {
1033 HWI2C_PortStatus *pStatus = NULL;
1034
1035 HWI2C_DBG_FUNC();
1036 if (!pParam_Status)
1037 return;
1038
1039 pStatus = (HWI2C_PortStatus *) pParam_Status;
1040
1041 if (pStatus->u8Port >= HWI2C_PORTS)
1042 return ;
1043
1044 HWI2C_MUTEX_LOCK(pStatus->u8Port);
1045 pStatus->bIsInit = _gbInit;
1046 pStatus->u8DbgLevel = _geDbgLv;
1047 pStatus->bIsMaster = HAL_HWI2C_IsMaster();
1048 pStatus->eState = _geStatePortGroup[pStatus->u8Port];
1049 HWI2C_MUTEX_UNLOCK(pStatus->u8Port);
1050 }
1051
1052 ////////////////////////////////////////////////////////////////////////////////
1053 /// @brief \b Function \b Name: MDrv_HWI2C_GetInfo
1054 /// @brief \b Function \b Description: Get HW I2C driver information
1055 /// @return \b HWI2C_Info*: Hw I2C drvier infroamtion
1056 ////////////////////////////////////////////////////////////////////////////////
MDrv_HWI2C_GetInfo()1057 const HWI2C_Info* MDrv_HWI2C_GetInfo()
1058 {
1059 HWI2C_DBG_FUNC();
1060 return (&_gsI2CInfo);
1061 }
1062
1063 ////////////////////////////////////////////////////////////////////////////////
1064 /// @brief \b Function \b Name: MDrv_HWI2C_ConfigDelay
1065 /// @brief \b Function \b Description: config delay parameter for START & STOP
1066 /// @param u32StartDelay \b IN: delay time (us) for after START
1067 /// @param u32StopDelay \b IN: delay time (us) for after STOP
1068 /// @return \b TRUE: Success FALSE: Fail
1069 ////////////////////////////////////////////////////////////////////////////////
MDrv_HWI2C_ConfigDelay(MS_U32 u32StartDelay,MS_U32 u32StopDelay)1070 MS_BOOL MDrv_HWI2C_ConfigDelay(MS_U32 u32StartDelay, MS_U32 u32StopDelay)
1071 {
1072 HWI2C_DBG_FUNC();
1073 MS_U8 u8Port;
1074 if(u32StartDelay < HWI2C_STARTDLY)
1075 {
1076 if(u32StartDelay==0)
1077 {
1078 HWI2C_DBG_ERR("START Delay 0(us) will cause accessing error !\n");
1079 }
1080 else
1081 {
1082 HWI2C_DBG_ERR("START Delay %d(us) will risk accessing error !\n",(int)u32StartDelay);
1083 }
1084 }
1085
1086 if(u32StopDelay < HWI2C_STOPDLY)
1087 {
1088 if(u32StopDelay==0)
1089 {
1090 HWI2C_DBG_ERR("STOP Delay 0(us) will cause accessing error !\n");
1091 }
1092 else
1093 {
1094 HWI2C_DBG_ERR("STOP Delay %d(us) will risk accessing error !\n",(int)u32StopDelay);
1095 }
1096 }
1097
1098 HWI2C_CONTROL_MUTEX_LOCK();
1099 u8Port =(MS_U8) g_u8SelectPort / 8;
1100
1101 if (u8Port >= HWI2C_PORTS)
1102 {
1103 HWI2C_DBG_ERR("Please first call API:MDrv_HWI2C_SelectPort() or use API:MDrv_HWI2C_ConfigDelay_EX()\n");
1104 HWI2C_CONTROL_MUTEX_UNLOCK();
1105 return FALSE;
1106 }
1107 g_u32StartDelay[u8Port] = u32StartDelay;
1108 g_u32StopDelay[u8Port] = u32StopDelay;
1109 HWI2C_DBG_INFO("Port:%d, u32StartDelay: %d(us)\n",u8Port, (int)g_u32StartDelay[u8Port]);
1110 HWI2C_DBG_INFO("Port:%d, u32StopDelay: %d(us)\n",u8Port,(int)g_u32StopDelay[u8Port]);
1111 HWI2C_CONTROL_MUTEX_UNLOCK();
1112
1113 return (((u32StartDelay==0)||(u32StopDelay==0))? FALSE : TRUE);
1114 }
1115
1116
1117 ////////////////////////////////////////////////////////////////////////////////
1118 /// @brief \b Function \b Name: MDrv_HWI2C_ConfigDelay_EX
1119 /// @brief \b Function \b Description: config delay parameter for START & STOP by every port
1120 /// @param HWI2C_DelayConfig \b IN:
1121 /// @return \b TRUE: Success FALSE: Fail
1122 ////////////////////////////////////////////////////////////////////////////////
1123
MDrv_HWI2C_ConfigDelay_EX(void * pParam_Config)1124 MS_BOOL MDrv_HWI2C_ConfigDelay_EX(void *pParam_Config)
1125 {
1126 HWI2C_DelayConfig *pConfig = NULL;
1127 MS_U8 u8Port;
1128 MS_U32 u32StartDelay;
1129 MS_U32 u32StopDelay;
1130
1131 if (!pParam_Config)
1132 return FALSE;
1133
1134 pConfig = (HWI2C_DelayConfig *) pParam_Config;
1135
1136 u8Port = pConfig->u8Port;
1137 u32StartDelay = pConfig->u32StartDelay;
1138 u32StopDelay = pConfig->u32StopDelay;
1139
1140 HWI2C_DBG_FUNC();
1141 HWI2C_DBG_INFO("%s-->Port:%d\n", __FUNCTION__, u8Port);
1142
1143 if(u32StartDelay < HWI2C_STARTDLY)
1144 {
1145 if(u32StartDelay==0)
1146 HWI2C_DBG_ERR("START Delay 0(us) will cause accessing error !\n");
1147 else
1148 HWI2C_DBG_ERR("START Delay %d(us) will risk accessing error !\n",(int)u32StartDelay);
1149 }
1150
1151 if(u32StopDelay < HWI2C_STOPDLY)
1152 {
1153 if(u32StopDelay==0)
1154 HWI2C_DBG_ERR("STOP Delay 0(us) will cause accessing error !\n");
1155 else
1156 HWI2C_DBG_ERR("STOP Delay %d(us) will risk accessing error !\n",(int)u32StopDelay);
1157 }
1158
1159 if (u8Port >= HWI2C_PORTS)
1160 {
1161 HWI2C_DBG_ERR("Port:%d is error Port setting will risk accessing error !\n",(int)u8Port);
1162 return FALSE;
1163 }
1164
1165 HWI2C_MUTEX_LOCK(u8Port);
1166 g_u32StartDelay[u8Port] = u32StartDelay;
1167 g_u32StopDelay[u8Port] = u32StopDelay;
1168 HWI2C_DBG_INFO("u32StartDelay: %d(us)\n", (int)g_u32StartDelay[u8Port]);
1169 HWI2C_DBG_INFO("u32StopDelay: %d(us)\n", (int)g_u32StopDelay[u8Port]);
1170 HWI2C_MUTEX_UNLOCK(u8Port);
1171
1172 return (((u32StartDelay==0)||(u32StopDelay==0))? FALSE : TRUE);
1173 }
1174
MDrv_HWI2C_SetPowerState(EN_POWER_MODE u16PowerState)1175 MS_U16 MDrv_HWI2C_SetPowerState(EN_POWER_MODE u16PowerState)
1176 {
1177 static EN_POWER_MODE _prev_u16PowerState = E_POWER_MECHANICAL;
1178 MS_U16 u16Return = FALSE;
1179 MS_U8 u8Port = 0;
1180
1181 if (u16PowerState == E_POWER_SUSPEND)
1182 {
1183 _prev_u16PowerState = u16PowerState;
1184 _gbInit = false;
1185 HWI2C_DBG_INFO("HWI2C_MUTEX_DELETE!\n");
1186 for (u8Port = 0; u8Port < (MS_U8)HWI2C_PORTS; u8Port++)
1187 {
1188 if (-1 != g_s32HWI2CMutex[u8Port])
1189 {
1190 HWI2C_MUTEX_DELETE(u8Port);
1191 }
1192 g_s32HWI2CMutex[u8Port] = -1;
1193 }
1194 HWI2C_CONTROL_MUTEX_DELETE();
1195 g_s32HWI2C_ControlMutex = -1;
1196 u16Return = 2;//SUSPEND_OK;
1197 }
1198 else if (u16PowerState == E_POWER_RESUME)
1199 {
1200
1201 if (_prev_u16PowerState == E_POWER_SUSPEND)
1202 {
1203 /* Support HW IIC interrupt mode */
1204 #ifdef CONFIG_HWIIC_INTERRUPT_MODE_ENABLE
1205 HAL_HWI2C_Resume_Flag(TRUE);
1206 #endif
1207 MDrv_HWI2C_Init(gp_HWI2CinitCfg);
1208 _prev_u16PowerState = u16PowerState;
1209 u16Return = 1;//RESUME_OK;
1210 }
1211 else
1212 {
1213 HWI2C_DBG_ERR("[%s,%5d]It is not suspended yet. We shouldn't resume\n",__FUNCTION__,__LINE__);
1214 u16Return = 3;//SUSPEND_FAILED;
1215 }
1216 }
1217 else
1218 {
1219 HWI2C_DBG_ERR("[%s,%5d]Do Nothing: %d\n",__FUNCTION__,__LINE__,u16PowerState);
1220 u16Return = FALSE;
1221 }
1222
1223 return u16Return;// for success
1224 }
1225
1226 #if (HWI2C_UTOPIA20)
1227 // below are utopia10 interface and will call to utopia20 core
_MDrv_HWI2C_CheckUtopia20Open(void ** pInstance,MS_U32 u32ModuleVersion,void * pAttribute)1228 MS_BOOL _MDrv_HWI2C_CheckUtopia20Open(void** pInstance, MS_U32 u32ModuleVersion, void* pAttribute)
1229 {
1230 if (FALSE == bU20HWI2COpened)
1231 {
1232 #if (HWI2C_KERNEL_MODE)
1233 if(UtopiaOpen(MODULE_HWI2C|KERNEL_MODE, pInstance, u32ModuleVersion, pAttribute) != UTOPIA_STATUS_SUCCESS)
1234 #else
1235 if(UtopiaOpen(MODULE_HWI2C, pInstance, u32ModuleVersion, pAttribute) != UTOPIA_STATUS_SUCCESS)
1236 #endif
1237 {
1238 //HWI2C_DBG_ERR("Open HWI2C fail\n");
1239 printf("HWI2C Open fail \n");
1240 return FALSE;
1241 }
1242 bU20HWI2COpened = TRUE;
1243 }
1244 return TRUE;
1245 }
1246 #endif
1247
MDrv_HWI2C_Start(void)1248 MS_BOOL MDrv_HWI2C_Start(void)
1249 {
1250 #if (HWI2C_UTOPIA20)
1251 MS_U32 u32Ret;
1252 if (FALSE == _MDrv_HWI2C_CheckUtopia20Open(&pInstantHwi2c, 0, pAttributeHwi2c))
1253 return 0;
1254 u32Ret = UtopiaIoctl(pInstantHwi2c,MDrv_CMD_HWI2C_Start,(MS_U32*)NULL);
1255 return (MS_BOOL)u32Ret;
1256 #else
1257 return MDrv_HWI2C_Start_U2K();
1258 #endif
1259 }
1260
MDrv_HWI2C_Stop(void)1261 MS_BOOL MDrv_HWI2C_Stop(void)
1262 {
1263 #if (HWI2C_UTOPIA20)
1264 MS_U32 u32Ret;
1265 if (FALSE == _MDrv_HWI2C_CheckUtopia20Open(&pInstantHwi2c, 0, pAttributeHwi2c))
1266 return 0;
1267 u32Ret = UtopiaIoctl(pInstantHwi2c,MDrv_CMD_HWI2C_Stop,(MS_U32*)NULL);
1268 return (MS_BOOL)u32Ret;
1269 #else
1270 return MDrv_HWI2C_Stop_U2K();
1271 #endif
1272 }
1273
MDrv_HWI2C_SelectPort(HWI2C_PORT ePort)1274 MS_BOOL MDrv_HWI2C_SelectPort(HWI2C_PORT ePort)
1275 {
1276 #if (HWI2C_UTOPIA20)
1277 MS_U32 u32Ret;
1278 PHWI2C_PRIVATE_PARAM_SelectPort pHwi2cParam_SelectPort = NULL;
1279 if (FALSE == _MDrv_HWI2C_CheckUtopia20Open(&pInstantHwi2c, 0, pAttributeHwi2c))
1280 return 0;
1281 pHwi2cParam_SelectPort = (PHWI2C_PRIVATE_PARAM_SelectPort)malloc(sizeof(HWI2C_PRIVATE_PARAM_SelectPort));
1282 pHwi2cParam_SelectPort->ePort=ePort;
1283 u32Ret = UtopiaIoctl(pInstantHwi2c,MDrv_CMD_HWI2C_SelectPort,(MS_U32*)pHwi2cParam_SelectPort);
1284 free(pHwi2cParam_SelectPort);
1285 return (MS_BOOL)u32Ret;
1286 #else
1287 return MDrv_HWI2C_SelectPort_U2K(ePort);
1288 #endif
1289 }
1290
MDrv_HWI2C_SetClk(HWI2C_CLKSEL eClk)1291 MS_BOOL MDrv_HWI2C_SetClk(HWI2C_CLKSEL eClk)
1292 {
1293 #if (HWI2C_UTOPIA20)
1294 MS_U32 u32Ret;
1295 PHWI2C_PRIVATE_PARAM_SetClk pHwi2cParam_SetClk = NULL;
1296 if (FALSE == _MDrv_HWI2C_CheckUtopia20Open(&pInstantHwi2c, 0, pAttributeHwi2c))
1297 return 0;
1298 pHwi2cParam_SetClk = (PHWI2C_PRIVATE_PARAM_SetClk)malloc(sizeof(HWI2C_PRIVATE_PARAM_SetClk));
1299 pHwi2cParam_SetClk->eClk=eClk;
1300 u32Ret = UtopiaIoctl(pInstantHwi2c,MDrv_CMD_HWI2C_SetClk,(MS_U32*)pHwi2cParam_SetClk);
1301 free(pHwi2cParam_SetClk);
1302 return (MS_BOOL)u32Ret;
1303 #else
1304 return MDrv_HWI2C_SetClk_U2K(eClk);
1305 #endif
1306 }
1307
MDrv_HWI2C_WriteBytes(MS_U16 u16SlaveCfg,MS_U32 uAddrCnt,MS_U8 * pRegAddr,MS_U32 uSize,MS_U8 * pData)1308 MS_BOOL MDrv_HWI2C_WriteBytes(MS_U16 u16SlaveCfg, MS_U32 uAddrCnt, MS_U8 *pRegAddr, MS_U32 uSize, MS_U8 *pData)
1309 {
1310 #if (HWI2C_UTOPIA20)
1311 MS_U32 u32Ret;
1312 MS_BOOL bResult;
1313 PHWI2C_PRIVATE_PARAM_WriteBytes pHwi2cParam_WriteBytes = NULL;
1314 if (FALSE == _MDrv_HWI2C_CheckUtopia20Open(&pInstantHwi2c, 0, pAttributeHwi2c))
1315 return 0;
1316 pHwi2cParam_WriteBytes = (PHWI2C_PRIVATE_PARAM_WriteBytes)malloc(sizeof(HWI2C_PRIVATE_PARAM_WriteBytes));
1317 pHwi2cParam_WriteBytes->u16SlaveCfg=u16SlaveCfg;
1318 pHwi2cParam_WriteBytes->uAddrCnt=uAddrCnt;
1319 pHwi2cParam_WriteBytes->pRegAddr=pRegAddr;
1320 pHwi2cParam_WriteBytes->uSize=uSize;
1321 pHwi2cParam_WriteBytes->pData=pData;
1322 u32Ret = UtopiaIoctl(pInstantHwi2c,MDrv_CMD_HWI2C_WriteBytes,(void*)pHwi2cParam_WriteBytes);
1323 bResult = pHwi2cParam_WriteBytes->bReturn;
1324 free(pHwi2cParam_WriteBytes);
1325 return (MS_BOOL)bResult;
1326 #else
1327 return MDrv_HWI2C_WriteBytes_U2K(u16SlaveCfg,uAddrCnt,pRegAddr,uSize,pData);
1328 #endif
1329 }
1330
MDrv_HWI2C_ReadBytes(MS_U16 u16SlaveCfg,MS_U32 uAddrCnt,MS_U8 * pRegAddr,MS_U32 uSize,MS_U8 * pData)1331 MS_BOOL MDrv_HWI2C_ReadBytes(MS_U16 u16SlaveCfg, MS_U32 uAddrCnt, MS_U8 *pRegAddr, MS_U32 uSize, MS_U8 *pData)
1332 {
1333 #if (HWI2C_UTOPIA20)
1334 MS_U32 u32Ret;
1335 MS_BOOL bResult;
1336 PHWI2C_PRIVATE_PARAM_ReadBytes pHwi2cParam_ReadBytes = NULL;
1337 if (FALSE == _MDrv_HWI2C_CheckUtopia20Open(&pInstantHwi2c, 0, pAttributeHwi2c))
1338 return 0;
1339 pHwi2cParam_ReadBytes = (PHWI2C_PRIVATE_PARAM_ReadBytes)malloc(sizeof(HWI2C_PRIVATE_PARAM_ReadBytes));
1340 pHwi2cParam_ReadBytes->u16SlaveCfg=u16SlaveCfg;
1341 pHwi2cParam_ReadBytes->uAddrCnt=uAddrCnt;
1342 pHwi2cParam_ReadBytes->pRegAddr=pRegAddr;
1343 pHwi2cParam_ReadBytes->uSize=uSize;
1344 pHwi2cParam_ReadBytes->pData=pData;
1345 u32Ret = UtopiaIoctl(pInstantHwi2c,MDrv_CMD_HWI2C_ReadBytes,(void*)pHwi2cParam_ReadBytes);
1346 bResult = pHwi2cParam_ReadBytes->bReturn;
1347 free(pHwi2cParam_ReadBytes);
1348 return (MS_BOOL)bResult;
1349 #else
1350 return MDrv_HWI2C_ReadBytes_U2K(u16SlaveCfg,uAddrCnt,pRegAddr,uSize,pData);
1351 #endif
1352 }
1353
1354
MDrv_HWI2C_Init(HWI2C_UnitCfg * psCfg)1355 MS_BOOL MDrv_HWI2C_Init(HWI2C_UnitCfg *psCfg)
1356 {
1357 #if (HWI2C_UTOPIA20)
1358 MS_U32 u32Ret;
1359 PHWI2C_PRIVATE_PARAM_Init pHwi2cParam_Init = NULL;
1360 if (FALSE == _MDrv_HWI2C_CheckUtopia20Open(&pInstantHwi2c, 0, pAttributeHwi2c))
1361 return 0;
1362 pHwi2cParam_Init = (PHWI2C_PRIVATE_PARAM_Init)malloc(sizeof(HWI2C_PRIVATE_PARAM_Init));
1363 pHwi2cParam_Init->psCfg = psCfg;
1364 u32Ret = UtopiaIoctl(pInstantHwi2c,MDrv_CMD_HWI2C_Init,(MS_U32*)pHwi2cParam_Init);
1365 free(pHwi2cParam_Init);
1366 return (MS_BOOL)u32Ret;
1367 #else
1368 return MDrv_HWI2C_Init_U2K(psCfg);
1369 #endif
1370 }
1371
MDrv_HWI2C_GetConfig(HWI2C_UnitCfg * psCfg)1372 MS_BOOL MDrv_HWI2C_GetConfig(HWI2C_UnitCfg *psCfg)
1373 {
1374 #if (HWI2C_UTOPIA20)
1375 MS_U32 u32Ret;
1376 PHWI2C_PRIVATE_PARAM_Init pHwi2cParam_Init = NULL;
1377 if (FALSE == _MDrv_HWI2C_CheckUtopia20Open(&pInstantHwi2c, 0, pAttributeHwi2c))
1378 return 0;
1379 pHwi2cParam_Init = (PHWI2C_PRIVATE_PARAM_Init)malloc(sizeof(HWI2C_PRIVATE_PARAM_Init));
1380 u32Ret = UtopiaIoctl(pInstantHwi2c,MDrv_CMD_HWI2C_GetConfig,pHwi2cParam_Init);
1381 psCfg=pHwi2cParam_Init->psCfg;
1382 free(pHwi2cParam_Init);
1383 return (MS_BOOL)u32Ret;
1384 #else
1385 #endif
1386 return true;
1387 }
1388
1389