xref: /utopia/UTPA2-700.0.x/modules/cmdq/hal/maxim/cmdq/halCMDQ.c (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
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) 2006-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 // file   halCMDQ.c
97 // @brief  CMDQ HAL
98 // @author MStar Semiconductor,Inc.
99 ////////////////////////////////////////////////////////////////////////////////////////////////////
100 
101 #include "MsCommon.h"
102 #include "regCMDQ.h"
103 #include "halCMDQ.h"
104 
105 #include "ULog.h"
106 #define TAG_HAL_CMDQ "HAL_CMDQ"
107 //--------------------------------------------------------------------------------------------------
108 //  Utility Functions
109 //--------------------------------------------------------------------------------------------------
_log(int lv,const char * fn,int ln,char * fmt,...)110 static void _log(int lv, const char *fn, int ln, char *fmt, ...) {
111     va_list ap;
112     char *tag[] = {"DBG", "ERR", "WTF"};
113     int i;
114     i = (lv==2)?3:1;
115     va_start(ap, fmt);
116 
117     do {
118         if(lv!=0) ULOGE(TAG_HAL_CMDQ, "\033[35m");
119         ULOGE(TAG_HAL_CMDQ, "[cmdq][%s][%s:%d] ", tag[lv], fn, ln);
120         if(lv!=0) ULOGE(TAG_HAL_CMDQ, "\033[m");
121         vprintf(fmt, ap);
122     } while(--i);
123     va_end(ap);
124 }
125 #define _dbg(fmt, ...) _log(0, __PRETTY_FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
126 #define _err(fmt, ...) _log(1, __PRETTY_FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
127 #define _cri(fmt, ...) _log(2, __PRETTY_FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
128 
129 //--------------------------------------------------------------------------------------------------
130 //  Driver Compiler Option
131 //--------------------------------------------------------------------------------------------------
132 
133 //--------------------------------------------------------------------------------------------------
134 //  TSP Hardware Abstraction Layer
135 //--------------------------------------------------------------------------------------------------
136 static MS_VIRT                  _u32RegBase[NUMBER_OF_CMDQ_HW] = { 0x0, 0x0 };
137 static REG_CMDQCtrl             *_CMDQCtrl[NUMBER_OF_CMDQ_HW] = { (REG_CMDQCtrl*)REG_CMDQCTRL_BASE,
138                                                                   (REG_CMDQCtrl*)REG_CMDQCTRL_BASE2 };
139 
140 #define REG32_W(reg, value)     do {    \
141                                     (reg)->H = ((value) >> 16); \
142                                     (reg)->L = ((value) & 0x0000FFFFUL);  \
143                                 } while(0)
144 
145 //--------------------------------------------------------------------------------------------------
146 //  Macro of bit operations
147 //--------------------------------------------------------------------------------------------------
148 
149 //---------------------------------------------------------------------------
150 ///concatenate (reg)->H and (reg)->L
151 /// @param  reg                     \b IN: concatenate data
152 //---------------------------------------------------------------------------
_CMDQ_REG32_R(REG32 * reg)153 MS_U32 _CMDQ_REG32_R(REG32 *reg)
154 {
155     MS_U32 value = 0x0;
156         value = (reg)->H << 16;
157         value |= (reg)->L;
158     return value;
159 }
160 
161 //--------------------------------------------------------------------------------------------------
162 //  Inline Function
163 //--------------------------------------------------------------------------------------------------
164 
HAL_CMDQ_SetBank(MS_U32 hnd,MS_VIRT u32BankAddr)165 void HAL_CMDQ_SetBank(MS_U32 hnd, MS_VIRT u32BankAddr)
166 {
167     _u32RegBase[hnd] = u32BankAddr;
168     if(hnd == 0)
169     {
170         _CMDQCtrl[hnd] = (REG_CMDQCtrl*)(_u32RegBase[hnd] + REG_CMDQCTRL_BASE);
171     }
172     else if (hnd == 1)
173     {
174         _CMDQCtrl[hnd] = (REG_CMDQCtrl*)(_u32RegBase[hnd] + REG_CMDQCTRL_BASE2);
175     }
176     else
177     {
178         _cri("INVALID HANDLE! %d\n", hnd);
179     }
180 
181     _dbg("\033[35m[HAL_CMDQ_SetBank] Set Verify Code Setting...\033[m\n");
182     *(MS_U32 *)(_u32RegBase[hnd] + 0x0025C) = 0x0001;  // 0x2 0025C, open this for using write_mask(SN only), this is a RIU setting, set to 1 for enable 16-bit mask/16-bit data, set to 0 for 32-bit data only(mali will failed if set to 1)
183     //*(MS_U32 *)(_u32RegBase[hnd] + 0x46A88) = 0x0080;  // 0x2 46A88
184     *(MS_U32 *)(_u32RegBase[hnd] + 0x47204UL) = 0x0000;  // 0x2 47204, Enable CMDQ wirte RIU  0x247204 >> 1 ==> 0x123902
185                                                   // bank 0x1239 h0001 set bit_12 to be 0(cmdq host access RIU will be secure, so that cmdq can access secure/non-secure bank)
186 }
187 
188 //---------------------------------------------------------------------------
189 ///set the element of _CMDQCtrl
190 ///  .CMDQ_Enable
191 ///  .CMDQ_Length_ReadMode
192 ///  .CMDQ_Mask_Setting
193 //---------------------------------------------------------------------------
HAL_CMDQ_Enable(MS_U32 hnd)194 void HAL_CMDQ_Enable(MS_U32 hnd)
195 {
196     REG32_W((&_CMDQCtrl[hnd]->CMDQ_Enable), _CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_Enable) | (CMDQ_CMDQ_EN));
197     REG32_W((&_CMDQCtrl[hnd]->CMDQ_Length_ReadMode), _CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_Length_ReadMode) | (CMDQ_REQ_LEN_MASK) | (CMDQ_REQ_TH_MASK) | (REQ_DMA_BURST_MODE));
198     REG32_W((&_CMDQCtrl[hnd]->CMDQ_Mask_Setting), _CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_Mask_Setting) | (CMDQ_MASK_BIT));
199 
200     // do not jump wait/polling_eq/polling_neq command while timer reaches, very important, set to 0
201     REG32_W((&_CMDQCtrl[hnd]->CMDQ_Tout_Base_Amount) , _CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_Tout_Base_Amount)&(TOUT_DO_NOT_JUMP));
202 }
203 
HAL_CMDQ_Stop(MS_U32 hnd)204 void HAL_CMDQ_Stop(MS_U32 hnd)
205 {
206     REG32_W((&_CMDQCtrl[hnd]->CMDQ_Enable), _CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_Enable) | (CMDQ_CMDQ_DISEN));
207 }
208 
209 //---------------------------------------------------------------------------
210 ///set the element of _CMDQCtrl
211 ///  .CMDQ_En_Clk_Miu
212 //---------------------------------------------------------------------------
HAL_CMDQ_Reset(MS_U32 hnd)213 void HAL_CMDQ_Reset(MS_U32 hnd)
214 {
215     REG32_W((&_CMDQCtrl[hnd]->CMDQ_En_Clk_Miu), _CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_En_Clk_Miu) | (CMDQ_SOFT_RSTZ));
216 }
217 
HAL_CMDQ_Set_Mode(MS_U32 hnd,MS_U32 ModeSel)218 MS_BOOL HAL_CMDQ_Set_Mode(MS_U32 hnd, MS_U32 ModeSel)
219 {
220     if(ModeSel == 1)
221     {
222         REG32_W((&_CMDQCtrl[hnd]->CMDQ_Trig_Mode) , _CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_Trig_Mode) | (CMDQ_CMD_BUF_DIRECT_MODE));
223         return TRUE;
224     }
225     else if(ModeSel == 0)
226     {
227         REG32_W((&_CMDQCtrl[hnd]->CMDQ_Trig_Mode) , _CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_Trig_Mode) | (CMDQ_CMD_INCREAMENT_MODE));
228         return TRUE;
229     }
230     else if(ModeSel == 4)
231     {
232         REG32_W((&_CMDQCtrl[hnd]->CMDQ_Trig_Mode) , _CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_Trig_Mode) | (CMDQ_RING_BUFFER_MODE));
233         return TRUE;
234     }
235     else
236     {
237         _err("\033[35mHAL_CMDQ_Set_Mode ERROR!! Unknown mode, ModeSel = %d\033[m\n", ModeSel); // joe.liu
238         return FALSE;
239     }
240 }
241 
HAL_CMDQ_Set_Start_Pointer(MS_U32 hnd,MS_PHY StartAddr)242 void HAL_CMDQ_Set_Start_Pointer(MS_U32 hnd, MS_PHY StartAddr)
243 {
244     REG32_W((&_CMDQCtrl[hnd]->CMDQ_Cmd_St_Ptr), StartAddr);
245     _dbg("\033[35mset SATRT_ADDR: %llu\033[m\n", (unsigned long long)StartAddr); // joe.liu
246 }
247 
HAL_CMDQ_Set_End_Pointer(MS_U32 hnd,MS_PHY EndAddr)248 void HAL_CMDQ_Set_End_Pointer(MS_U32 hnd, MS_PHY EndAddr)
249 {
250     REG32_W((&_CMDQCtrl[hnd]->CMDQ_Cmd_End_Ptr), EndAddr);
251     _dbg("\033[35mset END_ADDR: %llu\033[m\n", (unsigned long long)EndAddr); // joe.liu
252 }
253 
HAL_CMDQ_Set_Offset_Pointer(MS_U32 hnd,MS_U32 OffsetAddr)254 void HAL_CMDQ_Set_Offset_Pointer(MS_U32 hnd, MS_U32 OffsetAddr)
255 {
256     REG32_W((&_CMDQCtrl[hnd]->CMDQ_Cmd_End_Ptr) , OffsetAddr);
257 }
258 
HAL_CMDQ_Set_Timer(MS_U32 hnd,MS_U32 time)259 void HAL_CMDQ_Set_Timer(MS_U32 hnd, MS_U32 time)
260 {
261     REG32_W((&_CMDQCtrl[hnd]->CMDQ_Poll_Ratio_Wait_Time) , _CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_Poll_Ratio_Wait_Time) | time);
262     _dbg("\033[35mSet Timer: 0x%X\033[m\n", (unsigned int)time); // joe.liu
263 }
264 
HAL_CMDQ_Set_Ratio(MS_U32 hnd,MS_U32 Ratio)265 void HAL_CMDQ_Set_Ratio(MS_U32 hnd, MS_U32 Ratio)
266 {
267     REG32_W((&_CMDQCtrl[hnd]->CMDQ_Poll_Ratio_Wait_Time) ,_CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_Poll_Ratio_Wait_Time) | Ratio);
268     _dbg("\033[35mSet Ratio: 0x%X\033[m\n", (unsigned int)Ratio); // joe.liu
269 }
270 
HAL_CMDQ_Reset_Soft_Interrupt(MS_U32 hnd)271 void HAL_CMDQ_Reset_Soft_Interrupt(MS_U32 hnd)
272 {
273     REG32_W((&_CMDQCtrl[hnd]->CMDQ_Sw_Trig_Cap_Sel_Irq_Clr) , _CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_Sw_Trig_Cap_Sel_Irq_Clr)|(CMDQ_SOFT_INTER_CLR));
274 }
275 
HAL_CMDQ_Reset_Start_Pointer_bit(MS_U32 hnd)276 void HAL_CMDQ_Reset_Start_Pointer_bit(MS_U32 hnd)
277 {
278     REG32_W((&_CMDQCtrl[hnd]->CMDQ_Trig_Mode) , _CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_Trig_Mode)|(CMDQ_RST_CMD_ST_PTR_TRIG));
279 }
280 
HAL_CMDQ_Read_Soft_Interrupt(MS_U32 hnd)281 void HAL_CMDQ_Read_Soft_Interrupt(MS_U32 hnd)
282 {
283     _CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_Raw_Irq_Final_Irq);
284 }
285 
HAL_CMDQ_Read_Dec_Done(MS_U32 hnd)286 void HAL_CMDQ_Read_Dec_Done(MS_U32 hnd)
287 {
288     _CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_Raw_Irq_Final_Irq);
289 }
290 
291 //---------------------------------------------------------------------------
292 ///Trigger for update start pointer and end pointer
293 //---------------------------------------------------------------------------
HAL_CMDQ_Start(MS_U32 hnd)294 void HAL_CMDQ_Start(MS_U32 hnd)
295 {
296     REG32_W((&_CMDQCtrl[hnd]->CMDQ_Trig_Mode), _CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_Trig_Mode) | (CMDQ_MOV_CMD_PTR));
297 }
298 
HAL_CMDQ_Read_Dummy_Register(MS_U32 hnd)299 MS_U32 HAL_CMDQ_Read_Dummy_Register(MS_U32 hnd)
300 {
301     MS_U32 reg_value=0;
302     reg_value= _CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_dummy);
303     return reg_value;
304 }
305 
HAL_CMDQ_Write_Dummy_Register(MS_U32 hnd,MS_U32 DummyValue)306 void HAL_CMDQ_Write_Dummy_Register(MS_U32 hnd, MS_U32 DummyValue)
307 {
308     REG32_W((&_CMDQCtrl[hnd]->CMDQ_dummy), (_CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_dummy) & (CMDQ__DUMMY_WRITE_ZERO)) | DummyValue);
309 }
310 
HAL_CMDQ_Set_MIU_SELECT(MS_U32 hnd,MS_U32 miu_select)311 void HAL_CMDQ_Set_MIU_SELECT(MS_U32 hnd, MS_U32 miu_select)
312 {
313     if(miu_select == 1)
314     {
315         _dbg("\033[35mset miu_1\033[m\n");
316         REG32_W((&_CMDQCtrl[hnd]->CMDQ_Length_ReadMode) , (_CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_Length_ReadMode) | CMDQ_MIU_SELECT_MIU1));
317     }
318     else
319     {
320         _dbg("\033[35mset miu_0\033[m\n");
321         REG32_W((&_CMDQCtrl[hnd]->CMDQ_Length_ReadMode) , (_CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_Length_ReadMode) & ~(CMDQ_MIU_SELECT_MIU1)));
322     }
323 }
324 
HAL_CMDQ_Read_Start_Pointer(MS_U32 hnd)325 MS_U32 HAL_CMDQ_Read_Start_Pointer(MS_U32 hnd)
326 {
327     MS_U32 reg_value = 0;
328     reg_value= _CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_Cmd_St_Ptr);
329     return reg_value;
330 }
331 
HAL_CMDQ_Read_End_Pointer(MS_U32 hnd)332 MS_U32 HAL_CMDQ_Read_End_Pointer(MS_U32 hnd)
333 {
334     MS_U32 reg_value = 0;
335     reg_value= _CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_Cmd_End_Ptr);
336     return reg_value;
337 }
338 
339 //---------------------------------------------------------------------------
340 ///Set Previous Dummy Register bit to be 1(which means this CAF is already write to DRAM)
341 //---------------------------------------------------------------------------
HAL_CMDQ_Write_Dummy_Register_release_polling(MS_U32 hnd,MS_U32 Write_bit)342 void HAL_CMDQ_Write_Dummy_Register_release_polling(MS_U32 hnd, MS_U32 Write_bit)
343 {
344     REG32_W((&_CMDQCtrl[hnd]->CMDQ_dummy), SET_FLAG1(_CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_dummy), 0x0001 << Write_bit));
345 }
346 
HAL_CMDQ_Error_Command(MS_U32 hnd,MS_U32 select_bit)347 MS_U32 HAL_CMDQ_Error_Command(MS_U32 hnd, MS_U32 select_bit)
348 {
349     MS_U32 reg_value = 0;
350     REG32_W((&_CMDQCtrl[hnd]->CMDQ_Cmd_Sel_Decode_State), select_bit);
351     reg_value = _CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_Dma_State_Rb_Cmd) & 0x0000ffff;
352     return reg_value;
353 }
354 
HAL_CMDQ_Write_Pointer(MS_U32 hnd,MS_PHY Write_value)355 void HAL_CMDQ_Write_Pointer(MS_U32 hnd, MS_PHY Write_value)
356 {
357     REG32_W((&_CMDQCtrl[hnd]->CMDQ_Sw_Wr_Mi_Wadr), Write_value);
358 }
359 
360 //---------------------------------------------------------------------------
361 ///Set rd_mi_radr_trig to grab current read address pointer(rd_mi_radr will be store in CMDQ_Rd_Mi_Radr)
362 //---------------------------------------------------------------------------
HAL_CMDQ_Read_Pointer(MS_U32 hnd)363 MS_U32 HAL_CMDQ_Read_Pointer(MS_U32 hnd)
364 {
365     MS_U32 reg_value = 0;
366     REG32_W((&_CMDQCtrl[hnd]->CMDQ_Trig_Mode), _CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_Trig_Mode) | CMDQ_READ_TRIG);
367     reg_value = _CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_Rd_Mi_Radr);
368     return reg_value;
369 }
370 
371 //---------------------------------------------------------------------------
372 ///get the Write_Pointer(for multi-process, preventing write address is wrong(each process will start from Buffer_Start) ==> get current write_cmd ptr, next will write from here
373 //---------------------------------------------------------------------------
HAL_CMDQ_Get_Write_Pointer(MS_U32 hnd)374 MS_U32 HAL_CMDQ_Get_Write_Pointer(MS_U32 hnd)
375 {
376     MS_U32 reg_value = 0;
377     reg_value = _CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_Sw_Wr_Mi_Wadr);
378     return reg_value;
379 }
380 
381 //---------------------------------------------------------------------------
382 ///Force trigger signal on wait bus. (good for debug), current sigbits 0-15
383 //---------------------------------------------------------------------------
HAL_CMDQ_Trigger_Wait(MS_U32 hnd,MS_U32 sigbits)384 void HAL_CMDQ_Trigger_Wait(MS_U32 hnd, MS_U32 sigbits)
385 {
386     MS_U32 v;
387     v = _CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_Wait_Trig)&0xFFFF0000;
388     v = v|(sigbits&0x0000FFFF);
389 
390     //@FIXME, do we need skip mask here. or add individual function to set it.
391     REG32_W((&_CMDQCtrl[hnd]->CMDQ_Wait_Trig),v);
392     //@FIXME, do we need to recover skip mask bit, if we set above 2 line.
393 }
394 
395 //---------------------------------------------------------------------------
396 ///Skip WR[0] WAIT[1], POLLEQ[2], POLLNEQ[3] commands. EX. 0xF skip those 4 cmds.
397 //---------------------------------------------------------------------------
HAL_CMDQ_Skip_Commands(MS_U32 hnd,MS_U32 skipbits)398 void HAL_CMDQ_Skip_Commands(MS_U32 hnd, MS_U32 skipbits)
399 {
400     MS_U32 v;
401     //@FIXME, r0a0, active low, does it really active low???
402 
403     //we also set skip mask bit, to force skip even mask is not set.
404     v = _CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_Force_Skip);
405     if(skipbits & 0x01)
406         v |= 0x00000011;
407     else if(skipbits & 0x02)
408         v |= 0x00000022;
409     else if(skipbits & 0x03)
410         v |= 0x00000044;
411     else if(skipbits & 0x04)
412         v |= 0x00000088;
413 
414     REG32_W((&_CMDQCtrl[hnd]->CMDQ_Force_Skip),v);
415 }
416 
417 //---------------------------------------------------------------------------
418 ///Real CMDQ reset
419 //---------------------------------------------------------------------------
HAL_CMDQ_Reset2(MS_U32 hnd,MS_BOOL high)420 void HAL_CMDQ_Reset2(MS_U32 hnd, MS_BOOL high)
421 {
422     MS_U32 v;
423     v = _CMDQ_REG32_R(&_CMDQCtrl[hnd]->CMDQ_En_Clk_Miu);
424     if(high)
425         REG32_W((&_CMDQCtrl[hnd]->CMDQ_En_Clk_Miu), v | (CMDQ_SOFT_RSTZ_BIT));
426     else {
427         REG32_W((&_CMDQCtrl[hnd]->CMDQ_En_Clk_Miu), v & (~CMDQ_SOFT_RSTZ_BIT));
428     }
429 
430 }
431 
432 //---------------------------------------------------------------------------
433 ///Read misc status bits.
434 //---------------------------------------------------------------------------
HAL_CMDQ_Read_Misc_Status(MS_U32 hnd)435 MS_U32 HAL_CMDQ_Read_Misc_Status(MS_U32 hnd)
436 {
437     return _CMDQ_REG32_R((&_CMDQCtrl[hnd]->CMDQ_Cmd_Ptr_Vld));
438 }
439 
HAL_CMDQ_Set_Debug_Step_Mode(MS_U32 hnd,MS_BOOL on)440 void HAL_CMDQ_Set_Debug_Step_Mode(MS_U32 hnd, MS_BOOL on)
441 {
442     MS_U32 r;
443     r = _CMDQ_REG32_R((&_CMDQCtrl[hnd]->CMDQ_Cmd_Mode_Enable));
444     if(on)
445         r |= (CMDQ_DEBUG_MODE_ENABLE|CMDQ_DEBUG_ONESTEP_ENABLE);
446     else
447         r &= ~(CMDQ_DEBUG_MODE_ENABLE|CMDQ_DEBUG_ONESTEP_ENABLE);
448     REG32_W((&_CMDQCtrl[hnd]->CMDQ_Cmd_Mode_Enable), r);
449 }
450 
HAL_CMDQ_Get_Debug_Step_Mode(MS_U32 hnd)451 MS_U32 HAL_CMDQ_Get_Debug_Step_Mode(MS_U32 hnd)
452 {
453     return _CMDQ_REG32_R((&_CMDQCtrl[hnd]->CMDQ_Cmd_Mode_Enable));
454 }
455 
456 //---------------------------------------------------------------------------
457 ///Trigger one step when debug-mode, step-mode enabled.
458 //---------------------------------------------------------------------------
HAL_CMDQ_Debug_One_Step(MS_U32 hnd)459 void HAL_CMDQ_Debug_One_Step(MS_U32 hnd)
460 {
461     REG32_W((&_CMDQCtrl[hnd]->CMDQ_One_Step_Trig),
462             _CMDQ_REG32_R((&_CMDQCtrl[hnd]->CMDQ_One_Step_Trig))|CMDQ_DEBUG_ONESTEP);
463 }
464