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 * (C) Copyright MStarSemi 2012
80 *
81 * Embedded high-speed host electric test procedure
82 *
83 */
84 //#include <MsCommon.h> // NUSED
85
86 #include "include/drvList.h"
87
88 // USB related header files
89 //#include "drvUSB.h" // NUSED
90 #include "drvUsbd.h"
91 #include "drvEHCI.h"
92 #include "drvUSBHwCtl.h"
93 /* applying drvUSB.h (inside drvUSBHwCtl.h) */
94
issueSE0(struct usb_hcd * hcd)95 void issueSE0(struct usb_hcd *hcd)
96 {
97 struct cpe_dev *dev;
98 const struct device_s *__mptr = hcd->controller;
99 dev = (struct cpe_dev *)( (char *)__mptr - offsetof(struct cpe_dev,dev) );
100 U32 regUTMI = dev->utmibase;
101
102 diag_printf("SE0 on port %d\n", (int)hcd->host_id);
103 usb_writew(0x0e00, (void*) (regUTMI+0x10*2));
104 }
105
issueTestJ(struct usb_hcd * hcd)106 void issueTestJ(struct usb_hcd *hcd)
107 {
108 struct cpe_dev *dev;
109 const struct device_s *__mptr = hcd->controller;
110 dev = (struct cpe_dev *)( (char *)__mptr - offsetof(struct cpe_dev,dev) );
111 U32 regUHC = dev->uhcbase;
112 U32 regUTMI = dev->utmibase;
113
114 diag_printf("TEST_J on port %d\n", (int)hcd->host_id);
115 usb_writew(0x0, (void*) (regUTMI+0x2c*2));
116 usb_writew(0x0, (void*) (regUTMI+0x2e*2));
117 usb_writeb(usb_readb((void*)(regUHC+0x50*2)) | 0x01, (void*) (regUHC+0x50*2)); //enable test J
118 }
119
issueTestK(struct usb_hcd * hcd)120 void issueTestK(struct usb_hcd *hcd)
121 {
122 struct cpe_dev *dev;
123 const struct device_s *__mptr = hcd->controller;
124 dev = (struct cpe_dev *)( (char *)__mptr - offsetof(struct cpe_dev,dev) );
125 U32 regUHC = dev->uhcbase;
126 U32 regUTMI = dev->utmibase;
127
128 diag_printf("TEST_K on port %d\n", (int)hcd->host_id);
129 usb_writew(0x0, (void*) (regUTMI+0x2c*2));
130 usb_writew(0x0, (void*) (regUTMI+0x2e*2));
131 usb_writeb(usb_readb((void*)(regUHC+0x50*2)) | 0x02, (void*) (regUHC+0x50*2)); //enable test K
132 }
133
issueTestPacket(struct usb_hcd * hcd)134 void issueTestPacket(struct usb_hcd *hcd)
135 {
136 struct cpe_dev *dev;
137 const struct device_s *__mptr = hcd->controller;
138 dev = (struct cpe_dev *)( (char *)__mptr - offsetof(struct cpe_dev,dev) );
139 U32 regUTMI = dev->utmibase;
140
141 diag_printf("Test packet on port %d\n", (int)hcd->host_id);
142 usb_writew(0x0600, (void*) (regUTMI+0x14*2)); //
143 usb_writew(0x0038, (void*) (regUTMI+0x10*2)); //
144 usb_writew(0x0BFE, (void*) (regUTMI+0x32*2)); //
145 }
146
147 extern struct list_head *ms_qh_urb_transaction_EHSET (struct ehci_hcd *ehci, struct urb *urb, struct list_head *head, int iFlags, int iStage);
148 extern int ms_submit_async_EHSET (struct ehci_hcd *ehci, struct urb *urb, struct list_head *qtd_list, int mem_flags);
ms_ehci_urb_enqueue_EHSET(struct usb_hcd * hcd,struct urb * urb,int mem_flags)149 int ms_ehci_urb_enqueue_EHSET (
150 struct usb_hcd *hcd,
151 struct urb *urb,
152 int mem_flags
153 )
154 {
155 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
156 U32 i, val;
157 struct list_head qtd_list;
158 struct usb_api_data *awd = (struct usb_api_data *)urb->pContext;
159
160 ms_list_init (&qtd_list);
161 diag_printf("SETUP\n");
162 if (!ms_qh_urb_transaction_EHSET (ehci, urb, &qtd_list, mem_flags, 0))
163 return -ENOMEM;
164 val = ms_submit_async_EHSET (ehci, urb, &qtd_list, mem_flags);
165 if (val)
166 {
167 diag_printf("<ms_ehci_urb_enqueue_EHSET> submit setup fail!\n");
168 return val;
169 }
170 diag_printf("delay 15 seconds\t");
171 for (i=0; i<14; i++)
172 {
173 mdelay(1000);
174 diag_printf("+");
175 }
176 diag_printf("\n");
177 diag_printf("DATA/STATUS\n");
178 if (!ms_qh_urb_transaction_EHSET (ehci, urb, &qtd_list, mem_flags, 1))
179 return -ENOMEM;
180 awd->done = 0;
181 return ms_submit_async_EHSET (ehci, urb, &qtd_list, mem_flags);
182 }
183
184 #define TMODE_VID 0x1A0A
185 #define TMODE_TEST_SE0_NAK 0x0101
186 #define TMODE_TEST_J 0x0102
187 #define TMODE_TEST_K 0x0103
188 #define TMODE_TEST_PACKET 0x0104
189 #define TMODE_PORT_SUSPEND_RESUME 0x0106
190 #define TMODE_SINGLE_STEP_GET_DEV_DESC 0x0107
191 #define TMODE_SINGLE_STEP_SET_FEATURE 0x0108
192 #define TMODE_NO_SESSION_TRAN_TEST 0x0200
193 #define TMODE_UNSUPPORT_DEVICE_TEST 0x0201
ms_usb_test_proc_vid(U16 vid,U16 pid)194 int ms_usb_test_proc_vid(U16 vid, U16 pid)
195 {
196 if (vid == TMODE_VID)
197 {
198 if ((pid == TMODE_TEST_SE0_NAK) || (pid == TMODE_TEST_J) || (pid == TMODE_TEST_K) || (pid == TMODE_TEST_PACKET))
199 return 1;
200 else if ((pid == TMODE_NO_SESSION_TRAN_TEST) || (pid == TMODE_UNSUPPORT_DEVICE_TEST))
201 return 3; // through normal enumeration flow
202 else
203 return 2;
204 }
205 else
206 return 0;
207 }
208 #if 0 // NUSED
209 extern int ehci_urb_enqueue_tst (
210 struct usb_hcd *hcd,
211 struct urb *urb,
212 int mem_flags
213 );
214 #endif
ms_usb_high_speed_test_proc(struct usb_device * udev,int flag)215 void ms_usb_high_speed_test_proc(struct usb_device *udev, int flag)
216 {
217 struct usb_hcd *hcd = udev->bus->hcpriv;
218 U32 i;
219
220 if (flag == 1)
221 osapi_spin_lock_irq(&ehs_test_lock);
222 switch (udev->descriptor.idProduct)
223 {
224 case TMODE_TEST_SE0_NAK:
225 issueSE0(hcd);
226 break;
227 case TMODE_TEST_J:
228 issueTestJ(hcd);
229 break;
230 case TMODE_TEST_K:
231 issueTestK(hcd);
232 break;
233 case TMODE_TEST_PACKET:
234 issueTestPacket(hcd);
235 break;
236 case TMODE_SINGLE_STEP_GET_DEV_DESC:
237 diag_printf("Single step get device descriptor, delay 15 second\t");
238 for (i=0; i<14; i++)
239 {
240 mdelay(1000);
241 diag_printf("+");
242 }
243 diag_printf("\n");
244 ms_usb_get_dev_descriptor(udev);
245 break;
246 case TMODE_SINGLE_STEP_SET_FEATURE:
247 diag_printf("Single step set feature\n");
248 hcd->ms_urb_enqueue = ms_ehci_urb_enqueue_EHSET; // re-assign urb_enqueue
249 ms_usb_get_dev_descriptor(udev);
250 break;
251 default:
252 diag_printf("Not supported!!!\n");
253 }
254
255 if (flag == 2)
256 osapi_spin_lock_irq(&ehs_test_lock);
257 diag_printf("Embedded host test procedure end\n");
258 while(1); // pause here
259 }
260
261