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 drvNDS.c
98 /// @brief NDS Driver Interface
99 /// @author MStar Semiconductor Inc.
100 ///////////////////////////////////////////////////////////////////////////////////////////////////
101
102 //-------------------------------------------------------------------------------------------------
103 // Include Files
104 //-------------------------------------------------------------------------------------------------
105 #include "MsCommon.h" // MStar common .h
106 #include "drvMMIO.h"
107
108 #include "regNDS.h" // MStar NDS HAL
109 #include "drvNDS.h"
110 #include "halNDS.h"
111
112 #include "nds.h" // internal .h
113
114 #include "ddiNDS_HDI.h" // NDS CAHDI driver .h
115
116
117 //-------------------------------------------------------------------------------------------------
118 // Driver Compiler Options
119 //-------------------------------------------------------------------------------------------------
120
121 //-------------------------------------------------------------------------------------------------
122 // Local Defines
123 //-------------------------------------------------------------------------------------------------
124
125
126 //-------------------------------------------------------------------------------------------------
127 // Local Structurs
128 //-------------------------------------------------------------------------------------------------
129
130
131 //-------------------------------------------------------------------------------------------------
132 // Global Variables
133 //-------------------------------------------------------------------------------------------------
134
135
136 //-------------------------------------------------------------------------------------------------
137 // Local Variables
138 //-------------------------------------------------------------------------------------------------
139
140
141 //-------------------------------------------------------------------------------------------------
142 // Debug Functions
143 //-------------------------------------------------------------------------------------------------
144
145
146 //-------------------------------------------------------------------------------------------------
147 // Local Functions
148 //-------------------------------------------------------------------------------------------------
149
150
151 //-------------------------------------------------------------------------------------------------
152 // Global Functions
153 //-------------------------------------------------------------------------------------------------
NDS_DBG_PrintData(MS_U8 * pu8Data,MS_U16 u16DataLen)154 void NDS_DBG_PrintData(MS_U8 *pu8Data, MS_U16 u16DataLen)
155 {
156 int i;
157 //printf("(%d)>>", u16DataLen);
158 for (i = 0; i < u16DataLen; i++)
159 {
160 if ((i % 16) == 0)
161 {
162 NDS_DBG("\n ");
163 }
164 NDS_DBG(" %02X ", pu8Data[i]);
165 }
166 NDS_DBG("\n");
167 }
168
169
MDrv_NDS_Init(NDS_Param * param)170 NDS_Result MDrv_NDS_Init(NDS_Param *param)
171 {
172 MS_U32 u32BaseAddr, u32BaseSize;
173
174 if (FALSE == MDrv_MMIO_GetBASE(&u32BaseAddr, &u32BaseSize, MS_MODULE_NDS))
175 {
176 NDS_ERR("MDrv_MMIO_GetBASE fail\n");
177 return E_NDS_FAIL;
178 }
179 NDS_RegMap(u32BaseAddr);
180 if (FALSE == MDrv_MMIO_GetBASE(&u32BaseAddr, &u32BaseSize, MS_MODULE_NSK))
181 {
182 NDS_ERR("MDrv_MMIO_GetBASE fail\n");
183 return E_NDS_FAIL;
184 }
185 NDS_NSK_RegMap(u32BaseAddr);
186 if (FALSE == MDrv_MMIO_GetBASE(&u32BaseAddr, &u32BaseSize, MS_MODULE_HW))
187 {
188 NDS_ERR("MDrv_MMIO_GetBASE fail\n");
189 return E_NDS_FAIL;
190 }
191 NDS_HW_RegMap(u32BaseAddr);
192
193 NDS_CAM_Init();
194 NDS_FLT_Init(&(param->flt)); // ECM / EMM
195 NDS_SC_Init(&(param->sc)); // SC
196
197 #if 0
198 NDS_RASP_Init(&(param->rasp));
199 #endif
200
201
202 NDS_SC_Open();
203
204 //[NOTE] add for J2 to open NSK clk
205 HAL_NDS_PowCtrl(0, TRUE);
206
207 // Set Chip Magic Value //
208 HAL_NDS_InitMagic();
209
210
211 return E_NDS_OK;
212 }
213
214
MDrv_NDS_Exit(void)215 NDS_Result MDrv_NDS_Exit(void)
216 {
217 NDS_SC_Close();
218 NDS_SC_Exit();
219 NDS_FLT_Exit();
220 NDS_CAM_Exit();
221
222 return E_NDS_OK;
223 }
224
225
MDrv_NDS_PowerOff(void)226 NDS_Result MDrv_NDS_PowerOff(void)
227 {
228 MS_U32 u32BaseAddr, u32BaseSize;
229 int i;
230
231 NDS_ERR("%s : Force Power OFF [BEGIN]\n", __FUNCTION__);
232 NDS_ERR("%s : All MDrv_NDS_ is not accessible now\n", __FUNCTION__);
233
234 if (FALSE == MDrv_MMIO_GetBASE(&u32BaseAddr, &u32BaseSize, MS_MODULE_HW))
235 {
236 NDS_ERR("MDrv_MMIO_GetBASE fail\n");
237 return E_NDS_FAIL;
238 }
239 NDS_HW_RegMap(u32BaseAddr);
240
241 for (i = 0; i < NSK_DEV_NUM; i++)
242 {
243 HAL_NDS_PowCtrl(i, TRUE);
244 }
245
246 NDS_ERR("%s : Force Power OFF [COMPLETED]\n", __FUNCTION__);
247
248 return E_NDS_OK;
249 }
250
251
MDrv_NDS_GetCaps(NDS_Caps cap)252 MS_U32 MDrv_NDS_GetCaps(NDS_Caps cap)
253 {
254 // return HAL_NDS_GetCaps(cap);
255 switch (cap)
256 {
257 case E_NDS_CAP_ECM_NUM :
258 return NDS_CAM_ECM_FLT_NUM;
259
260 case E_NDS_CAP_EMM_NUM :
261 return NDS_CAM_EMM_BUF_NUM;
262
263 case E_NDS_CAP_BUF_PITCH :
264 return NDS_CAM_FLT_BUF_SIZE;
265
266 case E_NDS_CAP_BUF_ALIGN :
267 return NDS_CAM_FLT_BUF_ALIGN;
268
269 case E_NDS_CAP_BUF_TOTALSIZE :
270 return NDS_CAM_FLT_BUFS_SIZE;
271
272 case E_NDS_CAP_RASP_BUF_TOTALSIZE :
273 return NDS_RASP_ALL_BUF_SIZE;
274
275 default:
276 return 0;
277 }
278 }
279
280
MDrv_NDS_SetMagicValue(MS_U8 idx,MS_U16 word_0,MS_U16 word_1,MS_U16 word_2,MS_U16 word_3)281 NDS_Result MDrv_NDS_SetMagicValue(MS_U8 idx, MS_U16 word_0, MS_U16 word_1, MS_U16 word_2, MS_U16 word_3)
282 {
283 if (idx > 4)
284 {
285 return E_NDS_FAIL;
286 }
287
288 NDS_REG(REG_MAGIC_V(idx, 0)) = word_0;
289 NDS_REG(REG_MAGIC_V(idx, 1)) = word_1;
290 NDS_REG(REG_MAGIC_V(idx, 2)) = word_2;
291 NDS_REG(REG_MAGIC_V(idx, 3)) = word_3;
292
293 return E_NDS_OK;
294 }
295
296
MDrv_NDS_NSK_Open(MS_U32 nds_id)297 NDS_Result MDrv_NDS_NSK_Open(MS_U32 nds_id)
298 {
299 HAL_NDS_PowCtrl(nds_id, TRUE);
300
301 NDS_NSK_Init(nds_id);
302
303 return E_NDS_OK;
304 }
305
306
MDrv_NDS_NSK_Close(MS_U32 nds_id)307 NDS_Result MDrv_NDS_NSK_Close(MS_U32 nds_id)
308 {
309 NDS_NSK_Exit(nds_id);
310
311 HAL_NDS_PowCtrl(nds_id, FALSE);
312
313 return E_NDS_OK;
314 }
315
316
317