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 yor any information; or
62 // (c) conferring any license or right under any intellectual property right.
63 //
64 // 7. These terms shall be governed by and construed in accordance with the laws
65 // of Taiwan, R.O.C., excluding its conflict of law rules.
66 // Any and all dispute arising out hereof or related hereto shall be finally
67 // settled by arbitration referred to the Chinese Arbitration Association,
68 // Taipei in accordance with the ROC Arbitration Law and the Arbitration
69 // Rules of the Association by three (3) arbitrators appointed in accordance
70 // with the said Rules.
71 // The place of arbitra��cordance
72 // with the said Rules.
73 // The place of arbitration shall be in Taipei, Taiwan and the language shall
74 // be English.
75 // The arbitration award shall be final and binding to both parties.
76 //
77 //******************************************************************************
78 //<MStar Software>
79 ////////////////////////////////////////////////////////////////////////////////
80 //
81 // Copyright (c) 2008-2009 MStar Semiconductor, Inc.
82 // All rights reserved.
83 //
84 // Unless otherwise stipulated in writing, any and all information contained
85 // herein regardless in any format shall remain the sole proprietary of
86 // MStar Semiconductor Inc. and be kept in strict confidence
87 // ("MStar Confidential Information") by the recipient.
88 // Any unauthorized act including without limitation unauthorized disclosure,
89 // copying, use, reproduction, sale, distribution, modification, disassembling,
90 // reverse engineering and compiling of the contents of MStar Confidential
91 // Information is unlawful and strictly prohibited. MStar hereby reserves the
92 // rights to any and all damages, losses, costs and expenses resulting therefrom.
93 //
94 ////////////////////////////////////////////////////////////////////////////////
95
96 ///////////////////////////////////////////////////////////////////////////////////////////////////
97 ///
98 /// file drvDMD_ISDBT_v2.c
99 /// @brief DMD ISDBT Driver Interface
100 /// @author MStar Semiconductor Inc.
101 ///////////////////////////////////////////////////////////////////////////////////////////////////
102
103 //-------------------------------------------------------------------------------------------------
104 // Include Files
105 //-------------------------------------------------------------------------------------------------
106
107 #ifdef MSOS_TYPE_LINUX_KERNEL
108 #include <linux/string.h>
109 #else
110 #include <string.h>
111 #include <stdio.h>
112 #endif
113
114 #include "utopia.h"
115 #include "utopia_dapi.h"
116
117 #include "drvDMD_ISDBT_v2.h"
118
119 //-------------------------------------------------------------------------------------------------
120 // Driver Compiler Options
121 //-------------------------------------------------------------------------------------------------
122
123
124 //-------------------------------------------------------------------------------------------------
125 // Local Defines
126 //-------------------------------------------------------------------------------------------------
127
128 #ifdef MS_DEBUG
129 #define DMD_DBG(x) (x)
130 #else
131 #define DMD_DBG(x) //(x)
132 #endif
133
134 //-------------------------------------------------------------------------------------------------
135 // Local Structurs
136 //-------------------------------------------------------------------------------------------------
137
138 typedef enum _ISDBT_POOL_ID
139 {
140 ISDBT_POOL_ID_DMD0 = 0
141 } ISDBT_POOL_ID;
142
143 typedef struct DLL_PACKED _ISDBT_RESOURCE_PRIVATE
144 {
145 DMD_ISDBT_ResData sDMD_ISDBT_ResData[DMD_ISDBT_MAX_DEMOD_NUM];
146 } ISDBT_RESOURCE_PRIVATE, *PISDBT_RESOURCE_PRIVATE;
147
148 #ifdef UTPA2
149
150 typedef MS_BOOL (*IOCTL_ISDBT_SetDbgLevel)(DMD_ISDBT_DbgLv);
151 typedef DMD_ISDBT_Info* (*IOCTL_ISDBT_GetInfo)(void);
152 typedef MS_BOOL (*IOCTL_ISDBT_GetLibVer)(const MSIF_Version**);
153 typedef MS_BOOL (*IOCTL_ISDBT_Init)(MS_U8, DMD_ISDBT_InitData*, MS_U32);
154 typedef MS_BOOL (*IOCTL_ISDBT_Exit)(MS_U8);
155 typedef MS_U32 (*IOCTL_ISDBT_GetConfig)(MS_U8, DMD_ISDBT_InitData*);
156 typedef MS_BOOL (*IOCTL_ISDBT_GetFwVer)(MS_U8, MS_U16*);
157 typedef MS_BOOL (*IOCTL_ISDBT_AdvSetConfig)(MS_U8, DMD_ISDBT_DEMOD_TYPE, MS_BOOL);
158 typedef MS_U32 (*IOCTL_ISDBT_SetPowerState)(MS_U8, EN_POWER_MODE);
159 typedef DMD_ISDBT_LOCK_STATUS (*IOCTL_ISDBT_GetLock)(MS_U8, DMD_ISDBT_GETLOCK_TYPE);
160 typedef MS_BOOL (*IOCTL_ISDBT_GetModulationMode)(MS_U8, EN_ISDBT_Layer, sISDBT_MODULATION_MODE*);
161 typedef MS_BOOL (*IOCTL_ISDBT_GetSignalStrength)(MS_U8, MS_U16*);
162 typedef MS_BOOL (*IOCTL_ISDBT_GetFreqOffset)(MS_U8, DMD_ISDBT_CFO_DATA*);
163 typedef MS_U16 (*IOCTL_ISDBT_GetSignalQuality)(MS_U8);
164 typedef MS_U16 (*IOCTL_ISDBT_GetSignalQualityOfLayerA)(MS_U8);
165 typedef MS_U16 (*IOCTL_ISDBT_GetSignalQualityOfLayerB)(MS_U8);
166 typedef MS_U16 (*IOCTL_ISDBT_GetSignalQualityOfLayerC)(MS_U8);
167 typedef MS_U16 (*IOCTL_ISDBT_GetSignalQualityCombine)(MS_U8);
168 typedef MS_U8 (*IOCTL_ISDBT_GetSNR)(MS_U8, DMD_ISDBT_SNR_DATA*);
169 typedef MS_BOOL (*IOCTL_ISDBT_Read_PKT_ERR)(MS_U8, EN_ISDBT_Layer, MS_U16*);
170 typedef MS_BOOL (*IOCTL_ISDBT_GetPreViterbiBer)(MS_U8, DMD_ISDBT_GET_BER_VALUE*);
171 typedef MS_BOOL (*IOCTL_ISDBT_GetPostViterbiBer)(MS_U8, DMD_ISDBT_GET_BER_VALUE*);
172 typedef MS_BOOL (*IOCTL_ISDBT_SetSerialControl)(MS_U8, MS_U8);
173 typedef MS_BOOL (*IOCTL_ISDBT_IIC_BYPASS_MODE)(MS_U8, MS_BOOL);
174 typedef MS_BOOL (*IOCTL_ISDBT_SWITCH_SSPI_GPIO)(MS_U8, MS_BOOL);
175 typedef MS_BOOL (*IOCTL_ISDBT_GPIO_GET_LEVEL)(MS_U8, MS_U8, MS_BOOL*);
176 typedef MS_BOOL (*IOCTL_ISDBT_GPIO_SET_LEVEL)(MS_U8, MS_U8, MS_BOOL);
177 typedef MS_BOOL (*IOCTL_ISDBT_GPIO_OUT_ENABLE)(MS_U8, MS_U8, MS_BOOL);
178 typedef MS_BOOL (*IOCTL_ISDBT_GetReg)(MS_U8, MS_U16, MS_U8*);
179 typedef MS_BOOL (*IOCTL_ISDBT_SetReg)(MS_U8, MS_U16, MS_U8);
180
181 typedef struct _ISDBT_INSTANT_PRIVATE
182 {
183 IOCTL_ISDBT_SetDbgLevel fpSetDbgLevel;
184 IOCTL_ISDBT_GetInfo fpGetInfo;
185 IOCTL_ISDBT_GetLibVer fpGetLibVer;
186 IOCTL_ISDBT_Init fpInit;
187 IOCTL_ISDBT_Exit fpExit;
188 IOCTL_ISDBT_GetConfig fpGetConfig;
189 IOCTL_ISDBT_GetFwVer fpGetFwVer;
190 IOCTL_ISDBT_AdvSetConfig fpAdvSetConfig;
191 IOCTL_ISDBT_SetPowerState fpSetPowerState;
192 IOCTL_ISDBT_GetLock fpGetLock;
193 IOCTL_ISDBT_GetModulationMode fpGetModulationMode;
194 IOCTL_ISDBT_GetSignalStrength fpGetSignalStrength;
195 IOCTL_ISDBT_GetFreqOffset fpGetFreqOffset;
196 IOCTL_ISDBT_GetSignalQuality fpGetSignalQuality;
197 IOCTL_ISDBT_GetSignalQualityOfLayerA fpGetSignalQualityOfLayerA;
198 IOCTL_ISDBT_GetSignalQualityOfLayerB fpGetSignalQualityOfLayerB;
199 IOCTL_ISDBT_GetSignalQualityOfLayerC fpGetSignalQualityOfLayerC;
200 IOCTL_ISDBT_GetSignalQualityCombine fpGetSignalQualityCombine;
201 IOCTL_ISDBT_GetSNR fpGetSNR;
202 IOCTL_ISDBT_Read_PKT_ERR fpRead_PKT_ERR;
203 IOCTL_ISDBT_GetPreViterbiBer fpGetPreViterbiBer;
204 IOCTL_ISDBT_GetPostViterbiBer fpGetPostViterbiBer;
205 IOCTL_ISDBT_SetSerialControl fpSetSerialControl;
206 IOCTL_ISDBT_IIC_BYPASS_MODE fpIIC_BYPASS_MODE;
207 IOCTL_ISDBT_SWITCH_SSPI_GPIO fpSWITCH_SSPI_GPIO;
208 IOCTL_ISDBT_GPIO_GET_LEVEL fpGPIO_GET_LEVEL;
209 IOCTL_ISDBT_GPIO_SET_LEVEL fpGPIO_SET_LEVEL;
210 IOCTL_ISDBT_GPIO_OUT_ENABLE fpGPIO_OUT_ENABLE;
211 IOCTL_ISDBT_GetReg fpGetReg;
212 IOCTL_ISDBT_SetReg fpSetReg;
213 } ISDBT_INSTANT_PRIVATE;
214
215 //-------------------------------------------------------------------------------------------------
216 // Global Variables
217 //-------------------------------------------------------------------------------------------------
218
219 extern DMD_ISDBT_ResData *psDMD_ISDBT_ResData;
220
221 //-------------------------------------------------------------------------------------------------
222 // Local Variables
223 //-------------------------------------------------------------------------------------------------
224
225
226 //-------------------------------------------------------------------------------------------------
227 // Debug Functions
228 //-------------------------------------------------------------------------------------------------
229
230
231 //-------------------------------------------------------------------------------------------------
232 // Local Functions
233 //-------------------------------------------------------------------------------------------------
234
235
236 //-------------------------------------------------------------------------------------------------
237 // Global Functions
238 //-------------------------------------------------------------------------------------------------
239
ISDBTOpen(void ** ppInstance,MS_U32 u32ModuleVersion,void * pAttribute)240 MS_U32 ISDBTOpen(void** ppInstance, MS_U32 u32ModuleVersion, void* pAttribute)
241 {
242 ISDBT_INSTANT_PRIVATE *pIsdbtPri = NULL;
243 void *pIsdbtPriVoid = NULL;
244
245 DMD_DBG(printf("\n[ISDBT INFO] isdbt open"));
246
247 // instance is allocated here, also can allocate private for internal use, ex, BDMA_INSTANT_PRIVATE
248 UtopiaInstanceCreate(sizeof(ISDBT_INSTANT_PRIVATE), ppInstance);
249 // setup func in private and assign the calling func in func ptr in instance private
250 UtopiaInstanceGetPrivate(*ppInstance, &pIsdbtPriVoid);
251 pIsdbtPri = (ISDBT_INSTANT_PRIVATE*)pIsdbtPriVoid;
252
253 pIsdbtPri->fpSetDbgLevel = _MDrv_DMD_ISDBT_SetDbgLevel;
254 pIsdbtPri->fpGetInfo = _MDrv_DMD_ISDBT_GetInfo;
255 pIsdbtPri->fpGetLibVer = _MDrv_DMD_ISDBT_GetLibVer;
256 pIsdbtPri->fpInit = _MDrv_DMD_ISDBT_MD_Init;
257 pIsdbtPri->fpExit = _MDrv_DMD_ISDBT_MD_Exit;
258 pIsdbtPri->fpGetConfig = _MDrv_DMD_ISDBT_MD_GetConfig;
259 pIsdbtPri->fpAdvSetConfig = _MDrv_DMD_ISDBT_MD_AdvSetConfig;
260 pIsdbtPri->fpSetPowerState = _MDrv_DMD_ISDBT_MD_SetPowerState;
261 pIsdbtPri->fpGetLock = _MDrv_DMD_ISDBT_MD_GetLock;
262 pIsdbtPri->fpGetModulationMode = _MDrv_DMD_ISDBT_MD_GetModulationMode;
263 pIsdbtPri->fpGetSignalStrength = _MDrv_DMD_ISDBT_MD_GetSignalStrength;
264 pIsdbtPri->fpGetFreqOffset = _MDrv_DMD_ISDBT_MD_GetFreqOffset;
265 pIsdbtPri->fpGetSignalQuality = _MDrv_DMD_ISDBT_MD_GetSignalQuality;
266 pIsdbtPri->fpGetSignalQualityOfLayerA = _MDrv_DMD_ISDBT_MD_GetSignalQualityOfLayerA;
267 pIsdbtPri->fpGetSignalQualityOfLayerB = _MDrv_DMD_ISDBT_MD_GetSignalQualityOfLayerB;
268 pIsdbtPri->fpGetSignalQualityOfLayerC = _MDrv_DMD_ISDBT_MD_GetSignalQualityOfLayerC;
269 pIsdbtPri->fpGetSignalQualityCombine = _MDrv_DMD_ISDBT_MD_GetSignalQualityCombine;
270 pIsdbtPri->fpGetSNR = _MDrv_DMD_ISDBT_MD_GetSNR;
271 pIsdbtPri->fpRead_PKT_ERR = _MDrv_DMD_ISDBT_MD_Read_PKT_ERR;
272 pIsdbtPri->fpGetPreViterbiBer = _MDrv_DMD_ISDBT_MD_GetPreViterbiBer;
273 pIsdbtPri->fpGetPostViterbiBer = _MDrv_DMD_ISDBT_MD_GetPostViterbiBer;
274 pIsdbtPri->fpSetSerialControl = _MDrv_DMD_ISDBT_MD_SetSerialControl;
275 pIsdbtPri->fpIIC_BYPASS_MODE = _MDrv_DMD_ISDBT_MD_IIC_BYPASS_MODE;
276 pIsdbtPri->fpSWITCH_SSPI_GPIO = _MDrv_DMD_ISDBT_MD_SWITCH_SSPI_GPIO;
277 pIsdbtPri->fpGPIO_GET_LEVEL = _MDrv_DMD_ISDBT_MD_GPIO_GET_LEVEL;
278 pIsdbtPri->fpGPIO_SET_LEVEL = _MDrv_DMD_ISDBT_MD_GPIO_SET_LEVEL;
279 pIsdbtPri->fpGPIO_OUT_ENABLE = _MDrv_DMD_ISDBT_MD_GPIO_OUT_ENABLE;
280 pIsdbtPri->fpGetReg = _MDrv_DMD_ISDBT_MD_GetReg;
281 pIsdbtPri->fpSetReg = _MDrv_DMD_ISDBT_MD_SetReg;
282
283 return UTOPIA_STATUS_SUCCESS;
284 }
285
286 #if DMD_ISDBT_STR_EN
ISDBTStr(MS_U32 u32PowerState,void * pModule)287 MS_U32 ISDBTStr(MS_U32 u32PowerState, void* pModule)
288 {
289 void* pResource = NULL;
290 ISDBT_RESOURCE_PRIVATE* psISDBTResPri = NULL;
291
292 MS_U32 i = 0;
293 MS_U32 u32Ret = FALSE;
294
295 if (UtopiaResourceObtain(pModule, ISDBT_POOL_ID_DMD0, &pResource) != 0)
296 {
297 printf("UtopiaResourceObtainToInstant fail\n");
298 return UTOPIA_STATUS_ERR_RESOURCE;
299 }
300
301 if(UtopiaResourceGetPrivate(pResource,(void*)&psISDBTResPri) != 0)
302 {
303 printf("UtopiaResourceGetPrivate fail\n");
304 return UTOPIA_STATUS_FAIL;
305 }
306
307 psDMD_ISDBT_ResData = ((PISDBT_RESOURCE_PRIVATE)psISDBTResPri)->sDMD_ISDBT_ResData;
308
309 do
310 {
311 u32Ret=_MDrv_DMD_ISDBT_MD_SetPowerState(i++, u32PowerState);
312 } while (i < DMD_ISDBT_MAX_DEMOD_NUM && u32Ret);
313
314 UtopiaResourceRelease(pResource);
315
316 return (u32Ret ? UTOPIA_STATUS_SUCCESS : UTOPIA_STATUS_FAIL);
317
318 }
319 #endif
320
ISDBTIoctl(void * pInstance,MS_U32 u32Cmd,void * pArgs)321 MS_U32 ISDBTIoctl(void* pInstance, MS_U32 u32Cmd, void* pArgs)
322 {
323 void* pModule = NULL;
324 UtopiaInstanceGetModule(pInstance, &pModule);
325 void* pResource = NULL;
326 ISDBT_RESOURCE_PRIVATE* psISDBTResPri = NULL;
327 ISDBT_INSTANT_PRIVATE* psISDBTInstPri = NULL;
328 void* psISDBTInstPriVoid = NULL;
329 UtopiaInstanceGetPrivate(pInstance, (void**)&psISDBTInstPriVoid);
330 psISDBTInstPri = (ISDBT_INSTANT_PRIVATE*)psISDBTInstPriVoid;
331
332 MS_U32 u32Ret = FALSE;
333
334 if (UtopiaResourceObtain(pModule, ISDBT_POOL_ID_DMD0, &pResource) != 0)
335 {
336 DMD_DBG(printf("UtopiaResourceObtainToInstant fail\n"));
337 return UTOPIA_STATUS_ERR_RESOURCE;
338 }
339
340 if(UtopiaResourceGetPrivate(pResource,(void*)&psISDBTResPri) != 0)
341 {
342 printf("UtopiaResourceGetPrivate fail\n");
343 return UTOPIA_STATUS_FAIL;
344 }
345
346 psDMD_ISDBT_ResData = ((PISDBT_RESOURCE_PRIVATE)psISDBTResPri)->sDMD_ISDBT_ResData;
347
348 switch (u32Cmd)
349 {
350 case DMD_ISDBT_DRV_CMD_SetDbgLevel:
351 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_SetDbgLevel\n"));
352 u32Ret = psISDBTInstPri->fpSetDbgLevel(((PISDBT_DBG_LEVEL_PARAM)pArgs)->u8DbgLevel);
353 break;
354 case DMD_ISDBT_DRV_CMD_GetInfo:
355 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_GetInfo\n"));
356 ((PISDBT_GET_INFO_PARAM)pArgs)->pInfo = psISDBTInstPri->fpGetInfo();
357 u32Ret = TRUE;
358 break;
359 case DMD_ISDBT_DRV_CMD_GetLibVer:
360 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_GetLibVer\n"));
361 u32Ret = psISDBTInstPri->fpGetLibVer(((PISDBT_GET_LIB_VER_PARAM)pArgs)->ppVersion);
362 break;
363 case DMD_ISDBT_DRV_CMD_Init:
364 ((PISDBT_INIT_PARAM)pArgs)->id = 0;
365 case DMD_ISDBT_DRV_CMD_MD_Init:
366 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_MD_Init\n"));
367 u32Ret = psISDBTInstPri->fpInit(((PISDBT_INIT_PARAM)pArgs)->id, ((PISDBT_INIT_PARAM)pArgs)->pDMD_ISDBT_InitData, ((PISDBT_INIT_PARAM)pArgs)->u32InitDataLen);
368 break;
369 case DMD_ISDBT_DRV_CMD_Exit:
370 ((PISDBT_ID_PARAM)pArgs)->id = 0;
371 case DMD_ISDBT_DRV_CMD_MD_Exit:
372 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_MD_Exit\n"));
373 u32Ret = psISDBTInstPri->fpExit(((PISDBT_ID_PARAM)pArgs)->id);
374 break;
375 case DMD_ISDBT_DRV_CMD_GetConfig:
376 ((PISDBT_INIT_PARAM)pArgs)->id = 0;
377 case DMD_ISDBT_DRV_CMD_MD_GetConfig:
378 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_MD_GetConfig\n"));
379 u32Ret = psISDBTInstPri->fpGetConfig(((PISDBT_INIT_PARAM)pArgs)->id, ((PISDBT_INIT_PARAM)pArgs)->pDMD_ISDBT_InitData);
380 break;
381 case DMD_ISDBT_DRV_CMD_AdvSetConfig:
382 ((PISDBT_SET_CONFIG_PARAM)pArgs)->id = 0;
383 case DMD_ISDBT_DRV_CMD_MD_AdvSetConfig:
384 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_MD_SetConfig\n"));
385 u32Ret = psISDBTInstPri->fpAdvSetConfig(((PISDBT_SET_CONFIG_PARAM)pArgs)->id, ((PISDBT_SET_CONFIG_PARAM)pArgs)->eType, ((PISDBT_SET_CONFIG_PARAM)pArgs)->bEnable);
386 break;
387 case DMD_ISDBT_DRV_CMD_SetPowerState:
388 ((PISDBT_SET_POWER_STATE_PARAM)pArgs)->id = 0;
389 case DMD_ISDBT_DRV_CMD_MD_SetPowerState:
390 #if DMD_ISDBT_STR_EN
391 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_MD_SetPowerState\n"));
392 if (psISDBTInstPri->fpSetPowerState(((PISDBT_SET_POWER_STATE_PARAM)pArgs)->id, ((PISDBT_SET_POWER_STATE_PARAM)pArgs)->u16PowerState == UTOPIA_STATUS_SUCCESS))
393 u32Ret = TRUE;
394 else
395 u32Ret = FALSE;
396 #else
397 DMD_DBG(printf("ATSCIoctl - Don't support MDrv_DMD_ATSC_MD_SetPowerState\n"));
398 #endif
399 break;
400 case DMD_ISDBT_DRV_CMD_GetLock:
401 ((PISDBT_GET_LOCK_PARAM)pArgs)->id = 0;
402 case DMD_ISDBT_DRV_CMD_MD_GetLock:
403 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_MD_GetLock\n"));
404 ((PISDBT_GET_LOCK_PARAM)pArgs)->status = psISDBTInstPri->fpGetLock(((PISDBT_GET_LOCK_PARAM)pArgs)->id, ((PISDBT_GET_LOCK_PARAM)pArgs)->eType);
405 u32Ret = TRUE;
406 break;
407 case DMD_ISDBT_DRV_CMD_GetModulationMode:
408 ((PISDBT_GET_MODULATION_MODE_PARAM)pArgs)->id = 0;
409 case DMD_ISDBT_DRV_CMD_MD_GetModulationMode:
410 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_MD_GetModulationMode\n"));
411 u32Ret = psISDBTInstPri->fpGetModulationMode(((PISDBT_GET_MODULATION_MODE_PARAM)pArgs)->id, ((PISDBT_GET_MODULATION_MODE_PARAM)pArgs)->eLayerIndex, &(((PISDBT_GET_MODULATION_MODE_PARAM)pArgs)->IsdbtModulationMode));
412 break;
413 case DMD_ISDBT_DRV_CMD_GetSignalStrength:
414 ((PISDBT_GET_SIGNAL_STRENGTH_PARAM)pArgs)->id = 0;
415 case DMD_ISDBT_DRV_CMD_MD_GetSignalStrength:
416 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_MD_GetSignalStrength\n"));
417 u32Ret = psISDBTInstPri->fpGetSignalStrength(((PISDBT_GET_SIGNAL_STRENGTH_PARAM)pArgs)->id, &(((PISDBT_GET_SIGNAL_STRENGTH_PARAM)pArgs)->u16Strength));
418 break;
419 case DMD_ISDBT_DRV_CMD_GetSignalQuality:
420 case DMD_ISDBT_DRV_CMD_GetSignalQualityOfLayerA:
421 ((PISDBT_GET_SIGNAL_QUALITY_PARAM)pArgs)->id = 0;
422 case DMD_ISDBT_DRV_CMD_MD_GetSignalQuality:
423 case DMD_ISDBT_DRV_CMD_MD_GetSignalQualityOfLayerA:
424 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_MD_GetSignalQualityA\n"));
425 ((PISDBT_GET_SIGNAL_QUALITY_PARAM)pArgs)->u16SignalQuality = psISDBTInstPri->fpGetSignalQualityOfLayerA(((PISDBT_GET_SIGNAL_QUALITY_PARAM)pArgs)->id);
426 u32Ret = TRUE;
427 break;
428 case DMD_ISDBT_DRV_CMD_GetSignalQualityOfLayerB:
429 ((PISDBT_GET_SIGNAL_QUALITY_PARAM)pArgs)->id = 0;
430 case DMD_ISDBT_DRV_CMD_MD_GetSignalQualityOfLayerB:
431 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_MD_GetSignalQualityB\n"));
432 ((PISDBT_GET_SIGNAL_QUALITY_PARAM)pArgs)->u16SignalQuality = psISDBTInstPri->fpGetSignalQualityOfLayerB(((PISDBT_GET_SIGNAL_QUALITY_PARAM)pArgs)->id);
433 u32Ret = TRUE;
434 break;
435 case DMD_ISDBT_DRV_CMD_GetSignalQualityOfLayerC:
436 ((PISDBT_GET_SIGNAL_QUALITY_PARAM)pArgs)->id = 0;
437 case DMD_ISDBT_DRV_CMD_MD_GetSignalQualityOfLayerC:
438 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_MD_GetSignalQualityC\n"));
439 ((PISDBT_GET_SIGNAL_QUALITY_PARAM)pArgs)->u16SignalQuality = psISDBTInstPri->fpGetSignalQualityOfLayerC(((PISDBT_GET_SIGNAL_QUALITY_PARAM)pArgs)->id);
440 u32Ret = TRUE;
441 break;
442 case DMD_ISDBT_DRV_CMD_GetSignalQualityCombine:
443 ((PISDBT_GET_SIGNAL_QUALITY_PARAM)pArgs)->id = 0;
444 case DMD_ISDBT_DRV_CMD_MD_GetSignalQualityCombine:
445 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_MD_GetSignalQualityCombine\n"));
446 ((PISDBT_GET_SIGNAL_QUALITY_PARAM)pArgs)->u16SignalQuality = psISDBTInstPri->fpGetSignalQualityCombine(((PISDBT_GET_SIGNAL_QUALITY_PARAM)pArgs)->id);
447 u32Ret = TRUE;
448 break;
449 case DMD_ISDBT_DRV_CMD_GetSNR:
450 ((PISDBT_GET_SNR_PARAM)pArgs)->id = 0;
451 case DMD_ISDBT_DRV_CMD_MD_GetSNR:
452 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_MD_GetSNR\n"));
453 u32Ret = psISDBTInstPri->fpGetSNR(((PISDBT_GET_SNR_PARAM)pArgs)->id, &(((PISDBT_GET_SNR_PARAM)pArgs)->snr));
454 break;
455 case DMD_ISDBT_DRV_CMD_Read_PKT_ERR:
456 ((PISDBT_READ_PKT_ERR_PARAM)pArgs)->id = 0;
457 case DMD_ISDBT_DRV_CMD_MD_Read_PKT_ERR:
458 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_MD_Read_uCPKT_ERR\n"));
459 u32Ret = psISDBTInstPri->fpRead_PKT_ERR(((PISDBT_READ_PKT_ERR_PARAM)pArgs)->id, ((PISDBT_READ_PKT_ERR_PARAM)pArgs)->eIsdbtLayer, &(((PISDBT_READ_PKT_ERR_PARAM)pArgs)->u16PacketErr));
460 break;
461 case DMD_ISDBT_DRV_CMD_GetPreViterbiBer:
462 ((PISDBT_GET_BER_PARAM)pArgs)->id = 0;
463 case DMD_ISDBT_DRV_CMD_MD_GetPreViterbiBer:
464 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_MD_GetPreViterbiBer\n"));
465 u32Ret = psISDBTInstPri->fpGetPreViterbiBer(((PISDBT_GET_BER_PARAM)pArgs)->id, &(((PISDBT_GET_BER_PARAM)pArgs)->ber));
466 break;
467 case DMD_ISDBT_DRV_CMD_GetPostViterbiBer:
468 ((PISDBT_GET_BER_PARAM)pArgs)->id = 0;
469 case DMD_ISDBT_DRV_CMD_MD_GetPostViterbiBer:
470 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_MD_GetPostViterbiBer\n"));
471 u32Ret = psISDBTInstPri->fpGetPostViterbiBer(((PISDBT_GET_BER_PARAM)pArgs)->id, &(((PISDBT_GET_BER_PARAM)pArgs)->ber));
472 break;
473 case DMD_ISDBT_DRV_CMD_GetFreqOffset:
474 ((PISDBT_GET_FREQ_OFFSET_PARAM)pArgs)->id = 0;
475 case DMD_ISDBT_DRV_CMD_MD_GetFreqOffset:
476 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_MD_ReadFrequencyOffset\n"));
477 u32Ret = psISDBTInstPri->fpGetFreqOffset(((PISDBT_GET_FREQ_OFFSET_PARAM)pArgs)->id, &((PISDBT_GET_FREQ_OFFSET_PARAM)pArgs)->cfo);
478 break;
479 case DMD_ISDBT_DRV_CMD_SetSerialControl:
480 ((PISDBT_SET_SERIAL_CONTROL_PARAM)pArgs)->id = 0;
481 case DMD_ISDBT_DRV_CMD_MD_SetSerialControl:
482 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_MD_SetSerialControl\n"));
483 u32Ret = psISDBTInstPri->fpSetSerialControl(((PISDBT_SET_SERIAL_CONTROL_PARAM)pArgs)->id, ((PISDBT_SET_SERIAL_CONTROL_PARAM)pArgs)->u8TsConfigData);
484 break;
485 case DMD_ISDBT_DRV_CMD_IIC_BYPASS_MODE:
486 ((PISDBT_IIC_BYPASS_MODE_PARAM)pArgs)->id = 0;
487 case DMD_ISDBT_DRV_CMD_MD_IIC_BYPASS_MODE:
488 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_MD_IIC_BYPASS_MODE\n"));
489 u32Ret = psISDBTInstPri->fpIIC_BYPASS_MODE(((PISDBT_IIC_BYPASS_MODE_PARAM)pArgs)->id, ((PISDBT_IIC_BYPASS_MODE_PARAM)pArgs)->bEnable);
490 break;
491 case DMD_ISDBT_DRV_CMD_SWITCH_SSPI_GPIO:
492 ((PISDBT_SWITCH_SSPI_GPIO_PARAM)pArgs)->id = 0;
493 case DMD_ISDBT_DRV_CMD_MD_SWITCH_SSPI_GPIO:
494 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_MD_SWITCH_SSPI_GPIO\n"));
495 u32Ret = psISDBTInstPri->fpSWITCH_SSPI_GPIO(((PISDBT_SWITCH_SSPI_GPIO_PARAM)pArgs)->id, ((PISDBT_SWITCH_SSPI_GPIO_PARAM)pArgs)->bEnable);
496 break;
497 case DMD_ISDBT_DRV_CMD_GPIO_GET_LEVEL:
498 ((PISDBT_GPIO_LEVEL_PARAM)pArgs)->id = 0;
499 case DMD_ISDBT_DRV_CMD_MD_GPIO_GET_LEVEL:
500 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_MD_GPIO_GET_LEVEL\n"));
501 u32Ret = psISDBTInstPri->fpGPIO_GET_LEVEL(((PISDBT_GPIO_LEVEL_PARAM)pArgs)->id, ((PISDBT_GPIO_LEVEL_PARAM)pArgs)->u8Pin, &(((PISDBT_GPIO_LEVEL_PARAM)pArgs)->bLevel));
502 break;
503 case DMD_ISDBT_DRV_CMD_GPIO_SET_LEVEL:
504 ((PISDBT_GPIO_LEVEL_PARAM)pArgs)->id = 0;
505 case DMD_ISDBT_DRV_CMD_MD_GPIO_SET_LEVEL:
506 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_MD_GPIO_SET_LEVEL\n"));
507 u32Ret = psISDBTInstPri->fpGPIO_SET_LEVEL(((PISDBT_GPIO_LEVEL_PARAM)pArgs)->id, ((PISDBT_GPIO_LEVEL_PARAM)pArgs)->u8Pin, ((PISDBT_GPIO_LEVEL_PARAM)pArgs)->bLevel);
508 break;
509 case DMD_ISDBT_DRV_CMD_GPIO_OUT_ENABLE:
510 ((PISDBT_GPIO_OUT_ENABLE_PARAM)pArgs)->id = 0;
511 case DMD_ISDBT_DRV_CMD_MD_GPIO_OUT_ENABLE:
512 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_MD_GPIO_OUT_ENABLE\n"));
513 u32Ret = psISDBTInstPri->fpGPIO_OUT_ENABLE(((PISDBT_GPIO_OUT_ENABLE_PARAM)pArgs)->id, ((PISDBT_GPIO_OUT_ENABLE_PARAM)pArgs)->u8Pin, ((PISDBT_GPIO_OUT_ENABLE_PARAM)pArgs)->bEnableOut);
514 break;
515 case DMD_ISDBT_DRV_CMD_GetReg:
516 ((PISDBT_REG_PARAM)pArgs)->id = 0;
517 case DMD_ISDBT_DRV_CMD_MD_GetReg:
518 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_MD_GetReg\n"));
519 u32Ret = psISDBTInstPri->fpGetReg(((PISDBT_REG_PARAM)pArgs)->id, ((PISDBT_REG_PARAM)pArgs)->u16Addr, &(((PISDBT_REG_PARAM)pArgs)->u8Data));
520 break;
521 case DMD_ISDBT_DRV_CMD_SetReg:
522 ((PISDBT_REG_PARAM)pArgs)->id = 0;
523 case DMD_ISDBT_DRV_CMD_MD_SetReg:
524 DMD_DBG(printf("ISDBTIoctl - MDrv_DMD_ISDBT_MD_SetReg\n"));
525 u32Ret = psISDBTInstPri->fpSetReg(((PISDBT_REG_PARAM)pArgs)->id, ((PISDBT_REG_PARAM)pArgs)->u16Addr, ((PISDBT_REG_PARAM)pArgs)->u8Data);
526 break;
527 default:
528 break;
529 }
530
531 UtopiaResourceRelease(pResource);
532
533 return (u32Ret ? UTOPIA_STATUS_SUCCESS : UTOPIA_STATUS_FAIL);
534 }
535
ISDBTClose(void * pInstance)536 MS_U32 ISDBTClose(void* pInstance)
537 {
538 UtopiaInstanceDelete(pInstance);
539
540 return UTOPIA_STATUS_SUCCESS;
541 }
542
ISDBTRegisterToUtopia(FUtopiaOpen ModuleType)543 void ISDBTRegisterToUtopia(FUtopiaOpen ModuleType)
544 {
545 // 1. deal with module
546 void* pUtopiaModule = NULL;
547 UtopiaModuleCreate(MODULE_ISDBT, 8, &pUtopiaModule);
548 UtopiaModuleRegister(pUtopiaModule);
549 // register func for module, after register here, then ap call UtopiaOpen/UtopiaIoctl/UtopiaClose can call to these registered standard func
550 UtopiaModuleSetupFunctionPtr(pUtopiaModule, (FUtopiaOpen)ISDBTOpen, (FUtopiaClose)ISDBTClose, (FUtopiaIOctl)ISDBTIoctl);
551 // register func for module, after register here, then ap call UtopiaSTR can call to registered standard func
552 #if DMD_ISDBT_STR_EN
553 UtopiaModuleSetupSTRFunctionPtr(pUtopiaModule,(FUtopiaSTR)_MDrv_DMD_ISDBT_MD_SetPowerState);
554 #endif
555
556 // 2. deal with resource
557 void* psResource = NULL;
558 // start func to add res, call once will create 2 access in resource. Also can declare BDMA_POOL_ID_BDMA1 for another channel depend on driver owner.
559 UtopiaModuleAddResourceStart(pUtopiaModule, ISDBT_POOL_ID_DMD0);
560 // resource can alloc private for internal use, ex, BDMA_RESOURCE_PRIVATE
561 UtopiaResourceCreate("ISDBT", sizeof(ISDBT_RESOURCE_PRIVATE), &psResource);
562 // func to reg res
563 UtopiaResourceRegister(pUtopiaModule, psResource, ISDBT_POOL_ID_DMD0);
564 // end function to add res
565 UtopiaModuleAddResourceEnd(pUtopiaModule, ISDBT_POOL_ID_DMD0);
566 }
567
568 #endif // #ifdef UTPA2