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