xref: /utopia/UTPA2-700.0.x/modules/usb/drv/usb_ecos/usbhost/drvEHsTest.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 /*
79  * (C) Copyright MStarSemi 2012
80  *
81  * Embedded high-speed host electric test procedure
82  *
83  */
84 #include <MsCommon.h>
85 
86 #include  "include/drvConfig.h"
87 #include  "include/drvList.h"
88 
89 // USB related header files
90 #include "drvUSB.h"
91 #include "drvHCD.h"
92 #include "drvEHCI.h"
93 #include "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",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->mapbase;
112     U32 regUTMI = dev->utmibase;
113 
114     diag_printf("TEST_J on port %d\n",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->mapbase;
126     U32 regUTMI = dev->utmibase;
127 
128     diag_printf("TEST_K on port %d\n",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", 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 struct usb_api_data {
148   //wait_queue_head_t wqh;
149   int done;
150 };
151 extern struct list_head *qh_urb_transaction_EHSET (struct ehci_hcd *ehci, struct urb *urb, struct list_head *head, int flags, int stage);
152 extern int submit_async_EHSET (struct ehci_hcd *ehci, struct urb *urb, struct list_head *qtd_list, int mem_flags);
ehci_urb_enqueue_EHSET(struct usb_hcd * hcd,struct urb * urb,int mem_flags)153 int ehci_urb_enqueue_EHSET (
154   struct usb_hcd  *hcd,
155   struct urb  *urb,
156   int    mem_flags
157 )
158 {
159      struct ehci_hcd    *ehci = hcd_to_ehci (hcd);
160      U32 i, val;
161      struct list_head  qtd_list;
162      struct usb_api_data *awd = (struct usb_api_data *)urb->context;
163 
164      urb->transfer_flags &= ~EHCI_STATE_UNLINK;
165      INIT_LIST_HEAD (&qtd_list);
166      diag_printf("SETUP\n");
167      if (!qh_urb_transaction_EHSET (ehci, urb, &qtd_list, mem_flags, 0))
168         return -ENOMEM;
169      val =  submit_async_EHSET (ehci, urb, &qtd_list, mem_flags);
170      if (val)
171     {
172         diag_printf("<ehci_urb_enqueue_EHSET> submit setup fail!\n");
173         return val;
174     }
175      diag_printf("delay 15 seconds\t");
176      for (i=0; i<14; i++)
177      {
178          mdelay(1000);
179          diag_printf("+");
180      }
181      diag_printf("\n");
182      diag_printf("DATA/STATUS\n");
183      if (!qh_urb_transaction_EHSET (ehci, urb, &qtd_list, mem_flags, 1))
184          return -ENOMEM;
185      awd->done = 0;
186      return submit_async_EHSET (ehci, urb, &qtd_list, mem_flags);
187 }
188 
189 #define TMODE_VID                                       0x1A0A
190 #define TMODE_TEST_SE0_NAK                  0x0101
191 #define TMODE_TEST_J                                0x0102
192 #define TMODE_TEST_K                                0x0103
193 #define TMODE_TEST_PACKET                   0x0104
194 #define TMODE_PORT_SUSPEND_RESUME 0x0106
195 #define TMODE_SINGLE_STEP_GET_DEV_DESC 0x0107
196 #define TMODE_SINGLE_STEP_SET_FEATURE 0x0108
usb_test_proc_vid(U16 vid,U16 pid)197 int usb_test_proc_vid(U16 vid, U16 pid)
198 {
199     if (vid == TMODE_VID)
200     {
201         if ((pid == TMODE_TEST_SE0_NAK) || (pid == TMODE_TEST_J) || (pid == TMODE_TEST_K) || (pid == TMODE_TEST_PACKET))
202             return 1;
203         else
204             return 2;
205     }
206     else
207         return 0;
208 }
209 extern int ehci_urb_enqueue_tst (
210   struct usb_hcd  *hcd,
211   struct urb  *urb,
212   int    mem_flags
213 );
214 
usb_high_speed_test_proc(struct usb_device * udev,int flag)215 void 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         MsOS_DisableAllInterrupts();
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             usb_get_device_descriptor(udev);
245             break;
246         case TMODE_SINGLE_STEP_SET_FEATURE:
247             diag_printf("Single step set feature\n");
248             hcd->driver->urb_enqueue = ehci_urb_enqueue_EHSET; // re-assign urb_enqueue
249             usb_get_device_descriptor(udev);
250             break;
251         default:
252             diag_printf("Not supported!!!\n");
253     }
254 
255     if (flag == 2)
256         MsOS_DisableAllInterrupts();
257     diag_printf("Embedded host test procedure end\n");
258     while(1); // pause here
259 }
260 
261