int usb_init(void) { int result; void *ctrl; int i, start_index = 0; struct usb_device *dev; gpio_init_usb(1); running=0; dev_index=0; asynch_allowed=1; usb_hub_reset(); /* first make all devices unknown */ for (i = 0; i < USB_MAX_DEVICE; i++) { memset(&usb_dev[i], 0, sizeof(struct usb_device)); usb_dev[i].devnum = -1; } /* init low_level USB */ #define CONFIG_USB_MAX_CONTROLLER_COUNT 1 for (i = 0; i < CONFIG_USB_MAX_CONTROLLER_COUNT; i++) { /* init low_level USB */ printf("USB%d: ", i); if (usb_lowlevel_init(i, USB_INIT_HOST, &ctrl)) { puts("lowlevel init failed\n"); continue; } /* * lowlevel init is OK, now scan the bus for devices * i.e. search HUBs and configure them */ start_index = dev_index; printf("scanning bus %d for devices... ", i); dev = usb_alloc_new_device(ctrl); /* * device 0 is always present * (root hub, so let it analyze) */ if (dev) usb_new_device(dev); if (start_index == dev_index) puts("No USB Device found\n"); else printf("%d USB Device(s) found\n", dev_index - start_index); running = 1; } USB_PRINTF("scan end\n"); if (!running) { puts("USB error: all controllers failed lowlevel init\n"); return -1; } return 0; }
/*************************************************************************** * Init USB Device */ int usb_init(void) { void *ctrl; struct usb_device *dev; int i, start_index = 0; dev_index = 0; asynch_allowed = 1; usb_hub_reset(); /* first make all devices unknown */ for (i = 0; i < USB_MAX_DEVICE; i++) { memset(&usb_dev[i], 0, sizeof(struct usb_device)); usb_dev[i].devnum = -1; } /* init low_level USB */ for (i = 0; i < CONFIG_USB_MAX_CONTROLLER_COUNT; i++) { /* init low_level USB */ printf("USB%d: ", i); if (usb_lowlevel_init(i, USB_INIT_HOST, &ctrl)) { #if defined(CONFIG_OCTEON) && defined(CONFIG_OCTEON_OCX) if (i == 0) #endif puts("lowlevel init failed\n"); continue; } usb_controller_initialized[i] = true; /* * lowlevel init is OK, now scan the bus for devices * i.e. search HUBs and configure them */ start_index = dev_index; printf("scanning bus %d for devices... ", i); dev = usb_alloc_new_device(ctrl); /* * device 0 is always present * (root hub, so let it analyze) */ if (dev) usb_new_device(dev); if (start_index == dev_index) puts("No USB Device found\n"); else printf("%d USB Device(s) found\n", dev_index - start_index); usb_started = 1; } debug("scan end\n"); /* if we were not able to find at least one working bus, bail out */ if (!usb_started) { puts("USB error: all controllers failed lowlevel init\n"); return -1; } return 0; }
void usb_hub_port_connect_change(struct usb_device *dev, int port) { struct usb_device *usb; ALLOC_CACHE_ALIGN_BUFFER(struct usb_port_status, portsts, 1); unsigned short portstatus; /* Check status */ if (usb_get_port_status(dev, port + 1, portsts) < 0) { USB_HUB_PRINTF("get_port_status failed\n"); return; } portstatus = le16_to_cpu(portsts->wPortStatus); USB_HUB_PRINTF("portstatus %x, change %x, %s\n", portstatus, le16_to_cpu(portsts->wPortChange), portspeed(portstatus)); /* Clear the connection change status */ usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_C_CONNECTION); /* Disconnect any existing devices under this port */ if (((!(portstatus & USB_PORT_STAT_CONNECTION)) && (!(portstatus & USB_PORT_STAT_ENABLE))) || (dev->children[port])) { USB_HUB_PRINTF("usb_disconnect(&hub->children[port]);\n"); /* Return now if nothing is connected */ if (!(portstatus & USB_PORT_STAT_CONNECTION)) return; } /* Reset the port */ if (hub_port_reset(dev, port, &portstatus) < 0) { printf("cannot reset port %i!?\n", port + 1); return; } /* Allocate a new device struct for it */ usb = usb_alloc_new_device(dev->controller); if (portstatus & USB_PORT_STAT_HIGH_SPEED) usb->speed = USB_SPEED_HIGH; else if (portstatus & USB_PORT_STAT_LOW_SPEED) usb->speed = USB_SPEED_LOW; else usb->speed = USB_SPEED_FULL; dev->children[port] = usb; usb->parent = dev; usb->portnr = port + 1; /* Run it through the hoops (find a driver, etc) */ if (usb_new_device(usb)) { /* Woops, disable the port */ usb_free_device(); dev->children[port] = NULL; USB_HUB_PRINTF("hub: disabling port %d\n", port + 1); usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_ENABLE); } }
/*************************************************************************** * Init USB Device */ int usb_init(void) { void *ctrl; struct usb_device *dev; int i, start_index = 0; int controllers_initialized = 0; int ret; dev_index = 0; asynch_allowed = 1; usb_hub_reset(); /* first make all devices unknown */ for (i = 0; i < USB_MAX_DEVICE; i++) { memset(&usb_dev[i], 0, sizeof(struct usb_device)); usb_dev[i].devnum = -1; } /* init low_level USB */ for (i = 0; i < CONFIG_USB_MAX_CONTROLLER_COUNT; i++) { /* init low_level USB */ printf("USB%d: ", i); ret = usb_lowlevel_init(i, USB_INIT_HOST, &ctrl); if (ret == -ENODEV) { /* No such device. */ puts("Port not available.\n"); controllers_initialized++; continue; } if (ret) { /* Other error. */ puts("lowlevel init failed\n"); continue; } /* * lowlevel init is OK, now scan the bus for devices * i.e. search HUBs and configure them */ controllers_initialized++; start_index = dev_index; printf("scanning bus %d for devices... ", i); ret = usb_alloc_new_device(ctrl, &dev); if (ret) break; /* * device 0 is always present * (root hub, so let it analyze) */ ret = usb_new_device(dev); if (ret) usb_free_device(dev->controller); if (start_index == dev_index) { puts("No USB Device found\n"); continue; } else { printf("%d USB Device(s) found\n", dev_index - start_index); } usb_started = 1; } debug("scan end\n"); /* if we were not able to find at least one working bus, bail out */ if (controllers_initialized == 0) puts("USB error: all controllers failed lowlevel init\n"); return usb_started ? 0 : -ENODEV; }
int usb_hub_port_connect_change(struct usb_device *dev, int port) { ALLOC_CACHE_ALIGN_BUFFER(struct usb_port_status, portsts, 1); unsigned short portstatus; int ret, speed; /* Check status */ ret = usb_get_port_status(dev, port + 1, portsts); if (ret < 0) { debug("get_port_status failed\n"); return ret; } portstatus = le16_to_cpu(portsts->wPortStatus); debug("portstatus %x, change %x, %s\n", portstatus, le16_to_cpu(portsts->wPortChange), portspeed(portstatus)); /* Clear the connection change status */ usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_C_CONNECTION); /* Disconnect any existing devices under this port */ if (((!(portstatus & USB_PORT_STAT_CONNECTION)) && (!(portstatus & USB_PORT_STAT_ENABLE))) || usb_device_has_child_on_port(dev, port)) { debug("usb_disconnect(&hub->children[port]);\n"); /* Return now if nothing is connected */ if (!(portstatus & USB_PORT_STAT_CONNECTION)) return -ENOTCONN; } mdelay(200); /* Reset the port */ ret = legacy_hub_port_reset(dev, port, &portstatus); if (ret < 0) { if (ret != -ENXIO) printf("cannot reset port %i!?\n", port + 1); return ret; } mdelay(200); switch (portstatus & USB_PORT_STAT_SPEED_MASK) { case USB_PORT_STAT_SUPER_SPEED: speed = USB_SPEED_SUPER; break; case USB_PORT_STAT_HIGH_SPEED: speed = USB_SPEED_HIGH; break; case USB_PORT_STAT_LOW_SPEED: speed = USB_SPEED_LOW; break; default: speed = USB_SPEED_FULL; break; } #ifdef CONFIG_DM_USB struct udevice *child; ret = usb_scan_device(dev->dev, port + 1, speed, &child); #else struct usb_device *usb; ret = usb_alloc_new_device(dev->controller, &usb); if (ret) { printf("cannot create new device: ret=%d", ret); return ret; } dev->children[port] = usb; usb->speed = speed; usb->parent = dev; usb->portnr = port + 1; /* Run it through the hoops (find a driver, etc) */ ret = usb_new_device(usb); if (ret < 0) { /* Woops, disable the port */ usb_free_device(dev->controller); dev->children[port] = NULL; } #endif if (ret < 0) { debug("hub: disabling port %d\n", port + 1); usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_ENABLE); } return ret; }
static void usb_hub_port_connect_change(struct usb_device *dev, int port) { struct usb_device *usb; struct usb_port_status portsts; unsigned short portstatus, portchange; /* Check status */ if (usb_get_port_status(dev, port + 1, &portsts) < 0) { dev_dbg(&dev->dev, "get_port_status failed\n"); return; } portstatus = le16_to_cpu(portsts.wPortStatus); portchange = le16_to_cpu(portsts.wPortChange); dev_dbg(&dev->dev, "portstatus %x, change %x, %s\n", portstatus, portchange, portspeed(portstatus)); /* Clear the connection change status */ usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_C_CONNECTION); /* Disconnect any existing devices under this port */ if (dev->children[port] && !(portstatus & USB_PORT_STAT_CONNECTION)) { dev_dbg(&dev->dev, "disconnect detected on port %d\n", port + 1); usb_remove_device(dev->children[port]); if (!dev->parent && dev->host->usbphy) usb_phy_notify_disconnect(dev->host->usbphy, dev->speed); return; } /* Remove disabled but connected devices */ if (dev->children[port] && !(portstatus & USB_PORT_STAT_ENABLE)) usb_remove_device(dev->children[port]); mdelay(200); /* Reset the port */ if (hub_port_reset(dev, port, &portstatus) < 0) { dev_warn(&dev->dev, "cannot reset port %i!?\n", port + 1); return; } mdelay(200); /* Allocate a new device struct for it */ usb = usb_alloc_new_device(); usb->dev.parent = &dev->dev; usb->host = dev->host; if (portstatus & USB_PORT_STAT_HIGH_SPEED) usb->speed = USB_SPEED_HIGH; else if (portstatus & USB_PORT_STAT_LOW_SPEED) usb->speed = USB_SPEED_LOW; else usb->speed = USB_SPEED_FULL; dev->children[port] = usb; usb->parent = dev; usb->portnr = port + 1; /* Run it through the hoops (find a driver, etc) */ if (usb_new_device(usb)) { /* Woops, disable the port */ dev_dbg(&dev->dev, "hub: disabling port %d\n", port + 1); usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_ENABLE); usb_free_device(usb); return; } if (!dev->parent && dev->host->usbphy) usb_phy_notify_connect(dev->host->usbphy, usb->speed); device_detect(&usb->dev); }