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 #if defined(MSOS_TYPE_NOS)
80
81 #include "../USBHostConfig.h"
82 #include <stdlib.h>
83 //#include <stdarg.h>
84 #ifndef ATV_SERISE_USE
85 #include <stdio.h>
86 #endif
87 #include <string.h>
88
89 //#include "chipset.h"
90 //#include "flib.h"
91 #ifndef ATV_SERISE_USE
92 #include "../../include/datatype.h"
93 #else
94 #include "UsbHostDataDef.h"
95 #endif
96 #include "../drvHostLib.h"
97 #include "../drvHost200.h"
98 //#include "Host20_AP_HID.h"
99 //#include "Host20_AP_Camera.h"
100 #include "../drvUsbMain.h"
101 #include "../drvscsi.h"
102 #ifdef ATV_SERISE_USE
103 #include "uart.h"
104 #endif
105
106 #include "MsCommon.h"
107 #include "MsIRQ.h"
108 #include "MsOS.h"
109
110 #define DRV_HOST_DBG(x) //x;
111
112
113 OTGH_PT_BLK_Struct OTGH_PT_BLK __attribute__ ((aligned (16)));
114 OTGH_PT_BLK_Struct *sOTGH_PT_BLK;
115
116 void OTGH_PT_Bulk_Init(void);
117
118
119 extern void Init_Mass_Storage_Structure(void);
120
121 extern qHD_Structure *pHost20_qHD_List_Control0,*pHost20_qHD_List_Control1;
122 extern qHD_Structure *pHost20_qHD_List_Bulk0,*pHost20_qHD_List_Bulk1;
123
124
125 //====================================================================
126 // * Function Name: OTGH_AP_Main
127 // * Description: Main menu of path test
128 // * Input: none
129 // * OutPut: none
130 //====================================================================
MassStorage_Init(void)131 BOOLEAN MassStorage_Init(void)
132 {
133
134 BOOLEAN result;
135
136
137 if (sAttachDevice.saCD[0].sInterface[0].bInterfaceClass!=0x08)
138 {
139 DRV_HOST_DBG(printf("not mass storage class!\n"));
140 return FALSE;
141 }
142 DRV_HOST_DBG(printf("Mass storage device..\n"));
143 Init_Mass_Storage_Structure();
144
145 OTGH_PT_Bulk_Init();
146
147 result=bSCSI_Initial();
148 if(!result)
149 {
150 MsOS_DelayTask(500); //081205 at SEC, disk needs more time for TUR OK
151 result=bSCSI_Initial();
152 }
153
154 return result;
155 }
156
157
158
159
160 #if 0
161 //====================================================================
162 // * Function Name: OTGH_PT_Bulk_Close
163 // * Description:
164 // * Input: none
165 // * OutPut: none
166 //====================================================================
167 void OTGH_PT_Bulk_Close(void)
168 {
169
170 //<5>.Hang the qHD
171 if (sAttachDevice.saCD[0].sInterface[0].sED[0].bED_bmAttributes==OTGH_ED_BULK)
172 { //<5.1>.stop Asynchronous Schedule
173 flib_Host20_Asynchronous_Setting(HOST20_Disable);
174 if (Host20_qHD_List_Bulk0.bMaxPacketSize1> 2) //larger than 512
175 {//Support only 2 QHD
176 mwHost20_CurrentAsynchronousAddr_Set(Host20_STRUCTURE_qHD_BASE_ADDRESS);
177 }
178 else
179 {
180 //<5.2>.Hang the qHD for ED0~ED3
181 SetPointer(&(Host20_qHD_List_Control1.bNextQHDPointer3),VirtoPhyAddr((UINT16)&Host20_qHD_List_Control0));
182
183 }
184
185 //<5.2>.Enable Asynchronous Schedule
186 flib_Host20_Asynchronous_Setting(HOST20_Enable);
187 }
188
189 }
190 #endif
191 extern void Dump_Data(UINT16 addr,UINT16 sz);
192 extern BOOLEAN FirstBulkOut,FirstBulkIn;
193
194 //====================================================================
195 // * Function Name: OTGH_PT_Bulk_Init
196 // * Description:
197 // * Input: none
198 // * OutPut: none
199 //====================================================================
OTGH_PT_Bulk_Init(void)200 void OTGH_PT_Bulk_Init(void)
201 {
202
203 UINT16 wMaxPacketSize;
204
205 // UINT8 *wTemp;
206
207 wMaxPacketSize=sAttachDevice.saCD[0].sInterface[0].sED[0].bED_wMaxPacketSizeHighByte;
208 wMaxPacketSize=(wMaxPacketSize<<8)+(sAttachDevice.saCD[0].sInterface[0].sED[0].bED_wMaxPacketSizeLowByte);
209
210
211
212 //<5>.Hook the qHD
213 if (sAttachDevice.saCD[0].sInterface[0].sED[0].bED_bmAttributes==OTGH_ED_BULK)
214 { //<5.1>.stop Asynchronous Schedule
215 //flib_Host20_Asynchronous_Setting(HOST20_Disable);
216 //mbHost20_USBCMD_AsynchronousEnable_Clr();
217
218 mbHost20_USBCMD_AsynchronousEnable_Clr();
219 while(mwHost20_USBSTS_AsynchronousStatus_Rd()>0);
220
221
222 //<5.2>.Hook the qHD for ED0~ED3
223 pHost20_qHD_List_Control1->bNextQHDPointer=(VirtoPhyAddr((U32)pHost20_qHD_List_Bulk0)>>5);
224 pHost20_qHD_List_Bulk0->bNextQHDPointer=(VirtoPhyAddr((U32)pHost20_qHD_List_Bulk1)>>5);
225 pHost20_qHD_List_Bulk1->bNextQHDPointer=(VirtoPhyAddr((U32)pHost20_qHD_List_Control0)>>5);
226
227
228
229
230 //<5.2>.Enable Asynchronous Schedule
231 //flib_Host20_Asynchronous_Setting(HOST20_Enable);
232
233 }
234
235
236 FirstBulkIn=TRUE;
237 FirstBulkOut=TRUE;
238
239 //Setting Max Packet Size and print message
240 wMaxPacketSize=sAttachDevice.saCD[0].sInterface[0].sED[0].bED_wMaxPacketSizeHighByte;
241 wMaxPacketSize=(wMaxPacketSize<<8)+(sAttachDevice.saCD[0].sInterface[0].sED[0].bED_wMaxPacketSizeLowByte);
242 pHost20_qHD_List_Bulk0->bMaxPacketSize=wMaxPacketSize;
243 pHost20_qHD_List_Bulk1->bMaxPacketSize=wMaxPacketSize; //Suppose In/Out have the same Max packet Size
244 pHost20_qHD_List_Bulk0->bDeviceAddress=sAttachDevice.bAdd;
245 pHost20_qHD_List_Bulk1->bDeviceAddress=sAttachDevice.bAdd;
246 pHost20_qHD_List_Bulk0->bEdNumber=(sAttachDevice.saCD[0].sInterface[0].sED[0].bED_EndpointAddress) & 0x0f; //set endpoint address
247 pHost20_qHD_List_Bulk1->bEdNumber=(sAttachDevice.saCD[0].sInterface[0].sED[1].bED_EndpointAddress) & 0x0f; //set endpoint address
248
249 //printf("add:%02bx\n",psDevice_AP->bAdd);
250 //printf("Endpoint 1 addr: %02bx\n", Host20_qHD_List_Bulk0.bEdNumber);
251 //printf("Endpoint 2 addr: %02bx\n", Host20_qHD_List_Bulk1.bEdNumber);
252
253
254 //printf(">>> Bulk In/Out Max Packet Size = %x\n",wMaxPacketSize);
255
256 //For Bulk Structure
257 //sOTGH_PT_BLK=( OTGH_PT_BLK_Struct *)flib_Host20_GetStructure(Host20_MEM_TYPE_4K_BUFFER);//2=>4kBuffer;
258 //sOTGH_PT_BLK=(OTGH_PT_BLK_Struct xdata *)OTGH_PT_BLK_DATA; //bulk QH data structure
259 //printf("PT_BLK:%x\n",(U16)&OTGH_PT_BLK);
260 //printf("OTGH_PT_BLK_DATA:%x\n",OTGH_PT_BLK_DATA);
261 //OTGH_PT_BLK.wDataRange=2*1024*1; ////2k
262
263
264 if (((sAttachDevice.saCD[0].sInterface[0].sED[0].bED_EndpointAddress)&BIT7)>0)
265 { OTGH_PT_BLK.bInQHDArrayNum=0;//Array 0 //for in 0, for out,1
266 OTGH_PT_BLK.bOutQHDArrayNum=1;//Array 0
267 }
268 else
269 {
270 OTGH_PT_BLK.bInQHDArrayNum=1;//Array 0 //for in 1 for out,0
271 OTGH_PT_BLK.bOutQHDArrayNum=0;//Array 0
272 }
273
274 OTGH_PT_BLK.bStatus = HOST20_OK;
275 }
276 #endif //#if defined(MSOS_TYPE_NOS)
277
278
279