xref: /utopia/UTPA2-700.0.x/modules/usb/drv/usb_ecos/usbhost/drvUSBDebug.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 
80 #include <MsCommon.h>
81 
82 #include  "include/drvConfig.h"
83 #include  "include/drvCompiler.h"
84 #include  "include/drvErrno.h"
85 #include  "include/drvPorts.h"
86 #include  "include/drvTimer.h"
87 #include  "include/drvList.h"
88 
89 
90 #include "include/drvUSB.h"
91 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
usb_show_endpoint(struct usb_host_endpoint * endpoint)92 static void usb_show_endpoint(struct usb_host_endpoint *endpoint)
93 {
94   usb_show_endpoint_descriptor(&endpoint->desc);
95 }
96 
97 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
usb_show_interface(struct usb_host_interface * altsetting)98 static void usb_show_interface(struct usb_host_interface *altsetting)
99 {
100   int i;
101 
102   usb_show_interface_descriptor(&altsetting->desc);
103 
104   for (i = 0; i < altsetting->desc.bNumEndpoints; i++)
105     usb_show_endpoint(altsetting->endpoint + i);
106 }
107 
108 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
usb_show_config(struct usb_host_config * config)109 static void usb_show_config(struct usb_host_config *config)
110 {
111   int ii, jj;
112   struct usb_interface *ifp;
113 
114   usb_show_config_descriptor(&config->desc);
115   for (ii = 0; ii < config->desc.bNumInterfaces; ii++) {
116     ifp = config->interface[ii];
117 
118     if (!ifp)
119       break;
120 
121     printk("\nInterface: %d\n", ii);
122     for (jj = 0; jj < ifp->num_altsetting; jj++)
123       usb_show_interface(ifp->altsetting + jj);
124   }
125 }
126 
127 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
usb_show_device(struct usb_device * dev)128 void usb_show_device(struct usb_device *dev)
129 {
130   int i;
131 
132   usb_show_device_descriptor(&dev->descriptor);
133   if (dev->descriptor.bNumConfigurations > 0) {
134     for (i = 0; i < dev->descriptor.bNumConfigurations; i++)
135       usb_show_config(dev->config + i);
136   }
137 }
138 
139 
140 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
usb_show_device_descriptor(struct usb_device_descriptor * desc)141 void usb_show_device_descriptor(struct usb_device_descriptor *desc)
142 {
143   if (!desc)
144   {
145     printk("desc is NULL\n");
146     return;
147   }
148   printk("  Len = %d\n", desc->bLength);
149   printk("  DescType = %x\n", desc->bDescriptorType);
150 
151   printk("  Ver = %x.%02x\n", desc->bcdUSB >> 8, desc->bcdUSB & 0xff);
152   printk("  VID:PID      = %04x:%04x\n", desc->idVendor, desc->idProduct);
153   printk("  MaxPktSize0      = %d\n", desc->bMaxPacketSize0);
154   printk("  NumConfig   = %d\n", desc->bNumConfigurations);
155   printk("  Dev Ver      = %x.%02x\n", desc->bcdDevice >> 8, desc->bcdDevice & 0xff);
156 
157   printk("  Dev Class:SubClass:Protocol = %02x:%02x:%02x\n",
158     desc->bDeviceClass, desc->bDeviceSubClass, desc->bDeviceProtocol);
159   switch (desc->bDeviceClass) {
160   case 0:
161     printk("    Per-interface classes\n");
162     break;
163   case USB_CLASS_AUDIO:
164     printk("    Audio class\n");
165     break;
166   case USB_CLASS_COMM:
167     printk("    Communications class\n");
168     break;
169   case USB_CLASS_HID:
170     printk("    HID class\n");
171     break;
172   case USB_CLASS_PRINTER:
173     printk("    Printer class\n");
174     break;
175   case USB_CLASS_STORAGE:
176     printk("    MSD class\n");
177     break;
178   case USB_CLASS_HUB:
179     printk("    Hub class\n");
180     break;
181   case USB_CLASS_VENDOR_SPEC:
182     printk("    Vendor device Class\n");
183     break;
184   default:
185     printk("    Unknown device Class\n");
186   }
187 }
188 
189 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
usb_show_config_descriptor(struct usb_config_descriptor * desc)190 void usb_show_config_descriptor(struct usb_config_descriptor *desc)
191 {
192   printk("Config Desc:\n");
193   printk("Len = %d\n",desc->bLength);
194   printk("DescType = %x\n", desc->bDescriptorType);
195   printk("TotalLen = %x\n", desc->wTotalLength);
196   printk("Interfaces = %x\n", desc->bNumInterfaces);
197   printk("ConfigValue = %x\n", desc->bConfigurationValue);
198   printk("Config = %x\n", desc->iConfiguration);
199   printk("Attr = %x\n", desc->bmAttributes);
200   printk("MaxPower = %d\n", desc->bMaxPower * 2);
201 }
202 
203 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
usb_show_interface_descriptor(struct usb_interface_descriptor * desc)204 void usb_show_interface_descriptor(struct usb_interface_descriptor *desc)
205 {
206   printk("Alt Setting: %d\n", desc->bAlternateSetting);
207   printk("Len = %d\n", desc->bLength);
208   printk("DescType = %x\n", desc->bDescriptorType);
209   printk("Interface = %x\n", desc->bInterfaceNumber);
210   printk("AltSetting = %x\n", desc->bAlternateSetting);
211   printk("NumEpts = %x\n", desc->bNumEndpoints);
212   printk("Interface Class:SubClass:Protocol =   %x:%x:%x\n",
213     desc->bInterfaceClass, desc->bInterfaceSubClass, desc->bInterfaceProtocol);
214   printk("Interface = %x\n", desc->iInterface);
215 }
216 
217 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
218 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
219 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
usb_show_endpoint_descriptor(struct usb_endpoint_descriptor * desc)220 void usb_show_endpoint_descriptor(struct usb_endpoint_descriptor *desc)
221 {
222   printk("Endpoint:\n");
223   printk("Len = %d\n", desc->bLength);
224   printk("DescType = %x\n", desc->bDescriptorType);
225   printk("EptAddress = %x\n", desc->bEndpointAddress);
226   printk("Attributes = %x\n", desc->bmAttributes);
227   printk("MaxPktSize = %x\n", desc->wMaxPacketSize);
228   printk("Interval = %x\n", desc->bInterval);
229 }
230 
231 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
232 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
usb_show_string(struct usb_device * dev,char * id,int index)233 void usb_show_string(struct usb_device *dev, char *id, int index)
234 {
235 #if 0
236   char *buf;
237 
238 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
239 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
240   if (!index)
241     return;
242 
243 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
244 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
245   if (!(buf = (char*) kmalloc(256, GFP_KERNEL)))
246     return;
247 
248 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
249   if (usb_string(dev, index, buf, 256) > 0)
250     {
251        dev_printk(KERN_INFO, &dev->dev, "%s: %s\n", id, buf);
252     }
253   kfree(buf);
254 #endif
255 }
256 
257 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
usb_dump_urb(struct urb * urb)258 void usb_dump_urb (struct urb *urb)
259 {
260 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
261   printk ("urb                   :%p\n", urb);
262 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
263   printk ("dev                   :%p\n", urb->dev);
264 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
265   printk ("pipe                  :%08X\n", urb->pipe);
266 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
267   printk ("status                :%d\n", urb->status);
268 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
269   printk ("transfer_flags        :%08X\n", urb->transfer_flags);
270 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
271   printk ("transfer_buffer       :%p\n", urb->transfer_buffer);
272 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
273   printk ("transfer_buffer_length:%d\n", urb->transfer_buffer_length);
274 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
275   printk ("actual_length         :%d\n", urb->actual_length);
276 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
277   printk ("setup_packet          :%p\n", urb->setup_packet);
278 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
279   printk ("start_frame           :%d\n", urb->start_frame);
280 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
281   printk ("number_of_packets     :%d\n", urb->number_of_packets);
282 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
283   printk ("interval              :%d\n", urb->interval);
284 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
285   printk ("error_count           :%d\n", urb->error_count);
286 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
287   printk ("context               :%p\n", urb->context);
288 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
289   printk ("complete              :%p\n", urb->complete);
290 }
291 
292