Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/drivers/usb/usb_tests.c need to be fixed.

0001 /*                    The Quest Operating System
0002  *  Copyright (C) 2005-2010  Richard West, Boston University
0003  *
0004  *  This program is free software: you can redistribute it and/or modify
0005  *  it under the terms of the GNU General Public License as published by
0006  *  the Free Software Foundation, either version 3 of the License, or
0007  *  (at your option) any later version.
0008  *
0009  *  This program is distributed in the hope that it will be useful,
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012  *  GNU General Public License for more details.
0013  *
0014  *  You should have received a copy of the GNU General Public License
0015  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0016  */
0017 
0018 #include "drivers/usb/usb_tests.h"
0019 #include "drivers/usb/usb.h"
0020 #include "drivers/usb/umsc.h"
0021 #include "util/printf.h"
0022 #include "kernel.h"
0023 
0024 #define DEBUG_USB_TEST
0025 
0026 #ifdef DEBUG_USB_TEST
0027 #define DLOG(fmt,...) DLOG_PREFIX("usb-test",fmt,##__VA_ARGS__)
0028 #else
0029 #define DLOG(fmt,...) ;
0030 #endif
0031 
0032 #define printf com1_printf
0033 #define print com1_puts
0034 #define putx  com1_putx
0035 #define putchar com1_putc
0036 
0037 void
0038 show_usb_regs (int bus, int dev, int func)
0039 {
0040   uint16_t base_addr = 0;
0041   uint32_t ldata = 0;
0042   uint16_t wdata = 0;
0043   uint8_t bdata = 0;
0044 #if 0
0045   print ("\nUHCI Controller PCI Register Address Map\n\n");
0046 
0047   wdata = pci_config_rd16 (bus, dev, func, 0x00);
0048   print ("VID: 0x");
0049   putx (wdata);
0050   putchar ('\n');
0051 
0052   wdata = pci_config_rd16 (bus, dev, func, 0x02);
0053   print ("DID: 0x");
0054   putx (wdata);
0055   putchar ('\n');
0056 
0057   wdata = pci_config_rd16 (bus, dev, func, 0x04);
0058   print ("PCICMD: 0x");
0059   putx (wdata);
0060   putchar ('\n');
0061 
0062   wdata = pci_config_rd16 (bus, dev, func, 0x06);
0063   print ("PCISTS: 0x");
0064   putx (wdata);
0065   putchar ('\n');
0066 
0067   bdata = pci_config_rd8 (bus, dev, func, 0x08);
0068   print ("RID: 0x");
0069   putx (bdata);
0070   putchar ('\n');
0071 
0072   bdata = pci_config_rd8 (bus, dev, func, 0x09);
0073   print ("PI: 0x");
0074   putx (bdata);
0075   putchar ('\n');
0076 
0077   bdata = pci_config_rd8 (bus, dev, func, 0x0A);
0078   print ("SCC: 0x");
0079   putx (bdata);
0080   putchar ('\n');
0081 
0082   bdata = pci_config_rd8 (bus, dev, func, 0x0B);
0083   print ("BCC: 0x");
0084   putx (bdata);
0085   putchar ('\n');
0086 
0087   bdata = pci_config_rd8 (bus, dev, func, 0x0D);
0088   print ("MLT: 0x");
0089   putx (bdata);
0090   putchar ('\n');
0091 
0092   bdata = pci_config_rd8 (bus, dev, func, 0x0E);
0093   print ("HEADTYP: 0x");
0094   putx (bdata);
0095   putchar ('\n');
0096 
0097   wdata = pci_config_rd16 (bus, dev, func, 0x20);
0098   print ("BASE: 0x");
0099   putx (wdata);
0100   putchar ('\n');
0101 
0102   wdata = pci_config_rd16 (bus, dev, func, 0x2C);
0103   print ("SVID: 0x");
0104   putx (wdata);
0105   putchar ('\n');
0106 
0107   wdata = pci_config_rd16 (bus, dev, func, 0x2E);
0108   print ("SID: 0x");
0109   putx (wdata);
0110   putchar ('\n');
0111 
0112   bdata = pci_config_rd8 (bus, dev, func, 0x3C);
0113   print ("INT_LN: 0x");
0114   putx (bdata);
0115   putchar ('\n');
0116 
0117   bdata = pci_config_rd8 (bus, dev, func, 0x3D);
0118   print ("INT_PN: 0x");
0119   putx (bdata);
0120   putchar ('\n');
0121 
0122   bdata = pci_config_rd8 (bus, dev, func, 0x60);
0123   print ("USB_RELNUM: 0x");
0124   putx (bdata);
0125   putchar ('\n');
0126 
0127   wdata = pci_config_rd16 (bus, dev, func, 0xC0);
0128   print ("USB_LEGKEY: 0x");
0129   putx (wdata);
0130   putchar ('\n');
0131 
0132   bdata = pci_config_rd8 (bus, dev, func, 0xC4);
0133   print ("USB_RES: 0x");
0134   putx (bdata);
0135   putchar ('\n');
0136 
0137   bdata = pci_config_rd8 (bus, dev, func, 0xC8);
0138   print ("CWP: 0x");
0139   putx (bdata);
0140   putchar ('\n');
0141 #endif
0142   base_addr = pci_config_rd16 (bus, dev, func, 0x20);
0143   base_addr &= 0xFFE0;
0144 
0145   print ("\nBase address for USB I/O Registers: 0x");
0146   putx (base_addr);
0147   putchar ('\n');
0148 
0149   print ("\nUSB I/O Registers\n\n");
0150 
0151   wdata = inw (base_addr + 0x00);
0152   print ("USBCMD: 0x");
0153   putx (wdata);
0154   putchar ('\n');
0155 
0156   wdata = inw (base_addr + 0x02);
0157   print ("USBSTS: 0x");
0158   putx (wdata);
0159   putchar ('\n');
0160 
0161   wdata = inw (base_addr + 0x04);
0162   print ("USBINTR: 0x");
0163   putx (wdata);
0164   putchar ('\n');
0165 
0166   wdata = inw (base_addr + 0x06);
0167   print ("FRNUM: 0x");
0168   putx (wdata);
0169   putchar ('\n');
0170 
0171   ldata = inl (base_addr + 0x08);
0172   print ("FRBASEADD: 0x");
0173   putx (ldata);
0174   putchar ('\n');
0175 
0176   bdata = inb (base_addr + 0x0C);
0177   print ("SOFMOD: 0x");
0178   putx (bdata);
0179   putchar ('\n');
0180 
0181   wdata = inw (base_addr + 0x10);
0182   print ("PORTSC0: 0x");
0183   putx (wdata);
0184   putchar ('\n');
0185 
0186   wdata = inw (base_addr + 0x12);
0187   print ("PORTSC1: 0x");
0188   putx (wdata);
0189   putchar ('\n');
0190 
0191   bdata = pci_config_rd8 (bus, dev, func, 0x3C);
0192   print ("INT_LN: 0x");
0193   putx (bdata);
0194   putchar ('\n');
0195 
0196   bdata = pci_config_rd8 (bus, dev, func, 0x3D);
0197   print ("INT_PN: 0x");
0198   putx (bdata);
0199   putchar ('\n');
0200 
0201 
0202   return;
0203 }
0204 
0205 sint
0206 umsc_bo_reset (uint address, uint interface_idx)
0207 {
0208   USB_DEV_REQ req;
0209   printf ("bmsc_reset (%d, %d)\n", address, interface_idx);
0210   memset (&req, 0, sizeof (req));
0211   req.bmRequestType = 0x21;
0212   req.bRequest = 0xFF;
0213   req.wIndex = interface_idx;
0214   /* We assume this is a full speed device, use the maximum, 64 bytes */
0215   return uhci_control_transfer (address, (addr_t)&req, sizeof (req), 0, 0, 64);
0216 }
0217 
0218 void isochronous_transfer_test(void)
0219 {
0220   uint8_t data[20];
0221   uint8_t conf[1300];
0222 
0223   memset(data, 0, 20);
0224   USB_DEV_DESC *desc;
0225   USB_CFG_DESC *cfgd;
0226   UVC_IA_DESC *iad;
0227   USB_IF_DESC *vcifd;
0228   UVC_CSVC_IF_HDR_DESC *csvcifd;
0229   USB_DEVICE_INFO dev;
0230   dev.address = 0;
0231   dev.devd.bMaxPacketSize0 = 64;
0232   dev.host_type = USB_TYPE_HC_UHCI;
0233 
0234   port_reset(0);
0235   port_reset(1);
0236 
0237   usb_get_descriptor(&dev, USB_TYPE_DEV_DESC, 0, 0, 18, (addr_t)data);
0238   desc = (USB_DEV_DESC*)data;
0239   print("The length of device descriptor is: 0x");
0240   putx(desc->bLength);
0241   putchar('\n');
0242 
0243   port_reset(0);
0244   port_reset(1);
0245 
0246   print("Setting new address for the device.\n");
0247   if(usb_set_address(&dev, 1))
0248     DLOG("Set address failed!");
0249 
0250   dev.address = 1;
0251 
0252   memset(data, 0, 20);
0253 
0254   print("Now, getting device descriptor again.\n");
0255   usb_get_descriptor(&dev, USB_TYPE_DEV_DESC, 0, 0, 18, (addr_t)data);
0256   desc = (USB_DEV_DESC*)data;
0257 
0258 #if 1
0259   print("Device Descriptor: \n");
0260   print("  bLength : ");
0261   putx(desc->bLength);
0262   putchar('\n');
0263   print("  bDescriptorType : ");
0264   putx(desc->bDescriptorType);
0265   putchar('\n');
0266   print("  bcdUSB : ");
0267   putx(desc->bcdUSB);
0268   putchar('\n');
0269   print("  bDeviceClass : ");
0270   putx(desc->bDeviceClass);
0271   putchar('\n');
0272   print("  bDeviceSubClass : ");
0273   putx(desc->bDeviceSubClass);
0274   putchar('\n');
0275   print("  bDeviceProtocol : ");
0276   putx(desc->bDeviceProtocol);
0277   putchar('\n');
0278   print("  bMaxPacketSize0 : ");
0279   putx(desc->bMaxPacketSize0);
0280   putchar('\n');
0281   print("  idVendor : ");
0282   putx(desc->idVendor);
0283   putchar('\n');
0284   print("  idProduct : ");
0285   putx(desc->idProduct);
0286   putchar('\n');
0287   print("  bNumConfigurations : ");
0288   putx(desc->bNumConfigurations);
0289   putchar('\n');
0290 #endif
0291 
0292   memset(data, 0, 20);
0293 
0294   print("Getting configuration descriptor.\n");
0295   usb_get_descriptor(&dev, USB_TYPE_CFG_DESC, 0, 0, 9, (addr_t)data);
0296   cfgd = (USB_CFG_DESC*)data;
0297 
0298 #if 1
0299   print("Configuration Descriptor: \n");
0300   print("  bLength : ");
0301   putx(cfgd->bLength);
0302   putchar('\n');
0303   print("  bDescriptorType : ");
0304   putx(cfgd->bDescriptorType);
0305   putchar('\n');
0306   print("  wTotalLength : ");
0307   putx(cfgd->wTotalLength);
0308   putchar('\n');
0309   print("  bNumInterfaces : ");
0310   putx(cfgd->bNumInterfaces);
0311   putchar('\n');
0312   print("  bConfigurationValue : ");
0313   putx(cfgd->bConfigurationValue);
0314   putchar('\n');
0315   print("  iConfiguration : ");
0316   putx(cfgd->iConfiguration);
0317   putchar('\n');
0318   print("  bmAttributes : ");
0319   putx(cfgd->bmAttributes);
0320   putchar('\n');
0321   print("  MaxPower : ");
0322   putx(cfgd->MaxPower);
0323   putchar('\n');
0324 #endif
0325 
0326   memset(conf, 0, 1300);
0327 
0328   print("Getting all descriptors.\n");
0329   usb_get_descriptor(&dev, USB_TYPE_CFG_DESC, 0, 0, cfgd->wTotalLength, (addr_t)conf);
0330   iad = (UVC_IA_DESC*)(&conf[cfgd->bLength]);
0331 
0332 #if 1
0333   print("Interface Association Descriptor: \n");
0334   print("  bLength : ");
0335   putx(iad->bLength);
0336   putchar('\n');
0337   print("  bDescriptorType : ");
0338   putx(iad->bDescriptorType);
0339   putchar('\n');
0340   print("  bFirstInterface : ");
0341   putx(iad->bFirstInterface);
0342   putchar('\n');
0343   print("  bInterfaceCount : ");
0344   putx(iad->bInterfaceCount);
0345   putchar('\n');
0346   print("  bFunctionClass : ");
0347   putx(iad->bFunctionClass);
0348   putchar('\n');
0349   print("  bFunctionSubClass : ");
0350   putx(iad->bFunctionSubClass);
0351   putchar('\n');
0352   print("  bFunctionProtocol : ");
0353   putx(iad->bFunctionProtocol);
0354   putchar('\n');
0355   print("  iFunction : ");
0356   putx(iad->iFunction);
0357   putchar('\n');
0358 #endif
0359 
0360   vcifd = (USB_IF_DESC*)(&conf[cfgd->bLength + iad->bLength]);
0361 
0362 #if 1
0363   print("VC Interface Descriptor : \n");
0364   print("  bLength : ");
0365   putx(vcifd->bLength);
0366   putchar('\n');
0367   print("  bDescriptorType : ");
0368   putx(vcifd->bDescriptorType);
0369   putchar('\n');
0370   print("  bInterfaceNumber : ");
0371   putx(vcifd->bInterfaceNumber);
0372   putchar('\n');
0373   print("  bAlternateSetting : ");
0374   putx(vcifd->bAlternateSetting);
0375   putchar('\n');
0376   print("  bNumEndpoints : ");
0377   putx(vcifd->bNumEndpoints);
0378   putchar('\n');
0379   print("  bInterfaceClass : ");
0380   putx(vcifd->bInterfaceClass);
0381   putchar('\n');
0382   print("  bInterfaceSubClass : ");
0383   putx(vcifd->bInterfaceSubClass);
0384   putchar('\n');
0385   print("  bInterfaceProtocol : ");
0386   putx(vcifd->bInterfaceProtocol);
0387   putchar('\n');
0388   print("  iInterface : ");
0389   putx(vcifd->iInterface);
0390   putchar('\n');
0391 #endif
0392 
0393   csvcifd = (UVC_CSVC_IF_HDR_DESC*)(&conf[cfgd->bLength + iad->bLength + vcifd->bLength]);
0394 
0395 #if 1
0396   print("Class-Specific VC Interface Header Descriptor : \n");
0397   print("  bLength : ");
0398   putx(csvcifd->bLength);
0399   putchar('\n');
0400   print("  bDescriptorType : ");
0401   putx(csvcifd->bDescriptorType);
0402   putchar('\n');
0403   print("  bDescriptorSubType : ");
0404   putx(csvcifd->bDescriptorSubType);
0405   putchar('\n');
0406   print("  bcdUVC : ");
0407   putx(csvcifd->bcdUVC);
0408   putchar('\n');
0409   print("  wTotalLength : ");
0410   putx(csvcifd->wTotalLength);
0411   putchar('\n');
0412   print("  dwClockFrequency : ");
0413   putx(csvcifd->dwClockFrequency);
0414   putchar('\n');
0415   print("  bInCollection : ");
0416   putx(csvcifd->bInCollection);
0417   putchar('\n');
0418   print("  baInterface1 : ");
0419   putx(csvcifd->baInterface1);
0420   putchar('\n');
0421 #endif
0422 
0423   print("Set configuration to 1.\n");
0424   usb_set_configuration(&dev, 1);
0425 
0426   print("New configuration is : ");
0427   putx(usb_get_configuration(&dev));
0428   putchar('\n');
0429 
0430 #if 1
0431   memset(conf, 0, 1300);
0432 
0433   int status = usb_get_descriptor(&dev, USB_TYPE_CFG_DESC, 0, 0, 1000, (addr_t)conf);
0434   print("Status Code : ");
0435   putx(status);
0436   putchar('\n');
0437 
0438   uint32_t *dump = (uint32_t*)conf;
0439   int i = 0;
0440 
0441   for(i = 1; i < 200; i++) {
0442     putx(*dump);
0443     dump++;
0444     if(i%9 == 0) putchar('\n');
0445   }
0446 #endif
0447 
0448 }
0449 
0450 /*
0451  * Local Variables:
0452  * indent-tabs-mode: nil
0453  * mode: C
0454  * c-file-style: "gnu"
0455  * c-basic-offset: 2
0456  * End:
0457  */
0458 
0459 /* vi: set et sw=2 sts=2: */