static void usb_hub_port_connect_change(struct usb_hub *hubstate, int port, u16 portstatus, u16 portchange) { struct usb_device *hub = hubstate->dev; struct usb_device *dev; unsigned int delay = HUB_SHORT_RESET_TIME; int i; char *portstr, *tempstr; DBG_HOST_HUB("### >>> Enter hub.c file --> usb_hub_port_connect_change function \n"); dbg("port %d, portstatus %x, change %x, %s", port + 1, portstatus, portchange, portspeed (portstatus)); /* Clear the connection change status */ usb_clear_port_feature(hub, port + 1, USB_PORT_FEAT_C_CONNECTION); /* Disconnect any existing devices under this port */ if (hub->children[port]) usb_disconnect(&hub->children[port]); /* Return now if nothing is connected */ if (!(portstatus & USB_PORT_STAT_CONNECTION)) { if (portstatus & USB_PORT_STAT_ENABLE) usb_hub_port_disable(hub, port); return; } if (usb_hub_port_debounce(hub, port)) { err("connect-debounce failed, port %d disabled", port+1); usb_hub_port_disable(hub, port); return; } down(&usb_address0_sem); tempstr = kmalloc(1024, GFP_KERNEL); portstr = kmalloc(1024, GFP_KERNEL); for (i = 0; i < HUB_PROBE_TRIES; i++) { struct usb_device *pdev, *cdev; /* Allocate a new device struct */ dev = usb_alloc_dev(hub, hub->bus); if (!dev) { err("couldn't allocate usb_device"); break; } hub->children[port] = dev; /* Reset the device */ if (usb_hub_port_reset(hub, port, dev, delay)) { usb_free_dev(dev); break; } /* Find a new device ID for it */ usb_connect(dev); /* Set up TT records, if needed */ if (hub->tt) { dev->tt = hub->tt; dev->ttport = hub->ttport; } else if (dev->speed != USB_SPEED_HIGH && hub->speed == USB_SPEED_HIGH) { dev->tt = &hubstate->tt; dev->ttport = port + 1; } /* Create a readable topology string */ cdev = dev; pdev = dev->parent; if (portstr && tempstr) { portstr[0] = 0; while (pdev) { int port; for (port = 0; port < pdev->maxchild; port++) if (pdev->children[port] == cdev) break; strcpy(tempstr, portstr); if (!strlen(tempstr)) sprintf(portstr, "%d", port + 1); else sprintf(portstr, "%d/%s", port + 1, tempstr); cdev = pdev; pdev = pdev->parent; } info("USB new device connect on bus%d/%s, assigned device number %d", dev->bus->busnum, portstr, dev->devnum); } else info("USB new device connect on bus%d, assigned device number %d", dev->bus->busnum, dev->devnum); /* Run it through the hoops (find a driver, etc) */ if (!usb_new_device(dev)) goto done; /* Free the configuration if there was an error */ usb_free_dev(dev); /* Switch to a long reset time */ delay = HUB_LONG_RESET_TIME; } hub->children[port] = NULL; usb_hub_port_disable(hub, port); done: up(&usb_address0_sem); if (portstr) kfree(portstr); if (tempstr) kfree(tempstr); }
/* * WARNING - If a driver calls usb_reset_device, you should simulate a * disconnect() and probe() for other interfaces you doesn't claim. This * is left up to the driver writer right now. This insures other drivers * have a chance to re-setup their interface. * * Take a look at proc_resetdevice in devio.c for some sample code to * do this. */ int usb_reset_device(struct usb_device *dev) { struct usb_device *parent = dev->parent; struct usb_device_descriptor descriptor; int i, ret, port = -1; DBG_HOST_HUB("### >>> Enter hub.c file --> usb_reset_device function \n"); if (!parent) { err("attempting to reset root hub!"); return -EINVAL; } for (i = 0; i < parent->maxchild; i++) if (parent->children[i] == dev) { port = i; break; } if (port < 0) return -ENOENT; down(&usb_address0_sem); /* Send a reset to the device */ if (usb_hub_port_reset(parent, port, dev, HUB_SHORT_RESET_TIME)) { usb_hub_port_disable(parent, port); up(&usb_address0_sem); return(-ENODEV); } /* Reprogram the Address */ ret = usb_set_address(dev); if (ret < 0) { err("USB device not accepting new address (error=%d)", ret); usb_hub_port_disable(parent, port); up(&usb_address0_sem); return ret; } /* Let the SET_ADDRESS settle */ wait_ms(10); up(&usb_address0_sem); /* * Now we fetch the configuration descriptors for the device and * see if anything has changed. If it has, we dump the current * parsed descriptors and reparse from scratch. Then we leave * the device alone for the caller to finish setting up. * * If nothing changed, we reprogram the configuration and then * the alternate settings. */ ret = usb_get_descriptor(dev, USB_DT_DEVICE, 0, &descriptor, sizeof(descriptor)); if (ret < 0) return ret; le16_to_cpus(&descriptor.bcdUSB); le16_to_cpus(&descriptor.idVendor); le16_to_cpus(&descriptor.idProduct); le16_to_cpus(&descriptor.bcdDevice); if (memcmp(&dev->descriptor, &descriptor, sizeof(descriptor))) { usb_destroy_configuration(dev); ret = usb_get_device_descriptor(dev); if (ret < sizeof(dev->descriptor)) { if (ret < 0) err("unable to get device descriptor (error=%d)", ret); else err("USB device descriptor short read (expected %Zi, got %i)", sizeof(dev->descriptor), ret); clear_bit(dev->devnum, &dev->bus->devmap.devicemap); dev->devnum = -1; return -EIO; } ret = usb_get_configuration(dev); if (ret < 0) { err("unable to get configuration (error=%d)", ret); usb_destroy_configuration(dev); clear_bit(dev->devnum, &dev->bus->devmap.devicemap); dev->devnum = -1; return 1; } dev->actconfig = dev->config; usb_set_maxpacket(dev); return 1; } ret = usb_set_configuration(dev, dev->actconfig->bConfigurationValue); if (ret < 0) { err("failed to set active configuration (error=%d)", ret); return ret; } for (i = 0; i < dev->actconfig->bNumInterfaces; i++) { struct usb_interface *intf = &dev->actconfig->interface[i]; struct usb_interface_descriptor *as = &intf->altsetting[intf->act_altsetting]; ret = usb_set_interface(dev, as->bInterfaceNumber, as->bAlternateSetting); if (ret < 0) { err("failed to set active alternate setting for interface %d (error=%d)", i, ret); return ret; } } return 0; }
static void usb_hub_port_connect_change(struct usb_device *hub, int port, struct usb_port_status *portsts) { struct usb_device *dev; unsigned short portstatus, portchange; unsigned int delay = HUB_SHORT_RESET_TIME; int i; char *portstr, *tempstr; int devnum; portstatus = le16_to_cpu(portsts->wPortStatus); portchange = le16_to_cpu(portsts->wPortChange); dbg("port %d, portstatus %x, change %x, %s", port + 1, portstatus, portchange, portspeed (portstatus)); /* Clear the connection change status */ usb_clear_port_feature(hub, port + 1, USB_PORT_FEAT_C_CONNECTION); /* Disconnect any existing devices under this port */ down(&hub->bus->dev_tree_sem); if (hub->children[port]) usb_disconnect(&hub->children[port]); /* Return now if nothing is connected */ if (!(portstatus & USB_PORT_STAT_CONNECTION)) { if (portstatus & USB_PORT_STAT_ENABLE) usb_hub_port_disable(hub, port); up(&hub->bus->dev_tree_sem); return; } up(&hub->bus->dev_tree_sem); /* Some low speed devices have problems with the quick delay, so */ /* be a bit pessimistic with those devices. RHbug #23670 */ if (portstatus & USB_PORT_STAT_LOW_SPEED) { wait_ms(400); delay = HUB_LONG_RESET_TIME; } down(&usb_address0_sem); down(&hub->bus->dev_tree_sem); tempstr = kmalloc(1024, GFP_KERNEL); portstr = kmalloc(1024, GFP_KERNEL); for (i = 0; i < HUB_PROBE_TRIES; i++) { struct usb_device *pdev, *cdev; /* Allocate a new device struct */ dev = usb_alloc_dev(hub, hub->bus); if (!dev) { err("couldn't allocate usb_device"); break; } hub->children[port] = dev; /* Reset the device */ if (usb_hub_port_reset(hub, port, dev, delay)) { usb_free_dev(dev); break; } /* Find a new device ID for it */ usb_connect(dev); /* Create a readable topology string */ cdev = dev; pdev = dev->parent; if (portstr && tempstr) { portstr[0] = 0; while (pdev) { int port; for (port = 0; port < pdev->maxchild; port++) if (pdev->children[port] == cdev) break; strcpy(tempstr, portstr); if (!strlen(tempstr)) sprintf(portstr, "%d", port + 1); else sprintf(portstr, "%d/%s", port + 1, tempstr); cdev = pdev; pdev = pdev->parent; } info("USB new device connect on bus%d/%s, assigned device number %d", dev->bus->busnum, portstr, dev->devnum); } else info("USB new device connect on bus%d, assigned device number %d", dev->bus->busnum, dev->devnum); devnum = dev->devnum; /* Run it through the hoops (find a driver, etc) */ if (!usb_new_device(dev)) goto done; /* Free the configuration if there was an error */ usb_free_dev(dev); /* Switch to a long reset time */ delay = HUB_LONG_RESET_TIME; } err("failed adding a new device. Address=%d",devnum); hub->children[port] = NULL; usb_hub_port_disable(hub, port); done: up(&hub->bus->dev_tree_sem); up(&usb_address0_sem); if (portstr) kfree(portstr); if (tempstr) kfree(tempstr); }
static void usb_hub_port_connect_change(struct usb_hub *hubstate, int port, u16 portstatus, u16 portchange) { struct usb_device *hub = hubstate->dev; struct usb_device *dev; unsigned int delay = HUB_SHORT_RESET_TIME; int i; dbg("port %d, portstatus %x, change %x, %s", port + 1, portstatus, portchange, portspeed (portstatus)); /* Clear the connection change status */ usb_clear_port_feature(hub, port + 1, USB_PORT_FEAT_C_CONNECTION); /* Disconnect any existing devices under this port */ if (hub->children[port]) usb_disconnect(&hub->children[port]); /* Return now if nothing is connected */ if (!(portstatus & USB_PORT_STAT_CONNECTION)) { if (portstatus & USB_PORT_STAT_ENABLE) usb_hub_port_disable(hub, port); return; } if (usb_hub_port_debounce(hub, port)) { err("connect-debounce failed, port %d disabled", port+1); usb_hub_port_disable(hub, port); return; } down(&usb_address0_sem); for (i = 0; i < HUB_PROBE_TRIES; i++) { struct usb_device *pdev; int len; /* Allocate a new device struct */ dev = usb_alloc_dev(hub, hub->bus); if (!dev) { err("couldn't allocate usb_device"); break; } /* Reset the device */ if (usb_hub_port_reset(hub, port, dev, delay)) { usb_free_dev(dev); break; } /* Find a new device ID for it */ usb_connect(dev); /* Set up TT records, if needed */ if (hub->tt) { dev->tt = hub->tt; dev->ttport = hub->ttport; } else if (dev->speed != USB_SPEED_HIGH && hub->speed == USB_SPEED_HIGH) { dev->tt = &hubstate->tt; dev->ttport = port + 1; } /* Save readable and stable topology id, distinguishing * devices by location for diagnostics, tools, etc. The * string is a path along hub ports, from the root. Each * device's id will be stable until USB is re-cabled, and * hubs are often labeled with these port numbers. * * Initial size: ".NN" times five hubs + NUL = 16 bytes max * (quite rare, since most hubs have 4-6 ports). */ pdev = dev->parent; if (pdev->devpath [0] != '0') /* parent not root? */ len = snprintf (dev->devpath, sizeof dev->devpath, "%s.%d", pdev->devpath, port + 1); /* root == "0", root port 2 == "2", port 3 that hub "2.3" */ else len = snprintf (dev->devpath, sizeof dev->devpath, "%d", port + 1); if (len == sizeof dev->devpath) warn ("devpath size! usb/%03d/%03d path %s", dev->bus->busnum, dev->devnum, dev->devpath); USB_SET_LED(USB_CONNECT); //2005-02-24 by kanki for USB LED info("new USB device %s-%s, assigned address %d", dev->bus->bus_name, dev->devpath, dev->devnum); /* Run it through the hoops (find a driver, etc) */ if (!usb_new_device(dev)) { hub->children[port] = dev; goto done; } /* Free the configuration if there was an error */ usb_free_dev(dev); /* Switch to a long reset time */ delay = HUB_LONG_RESET_TIME; } usb_hub_port_disable(hub, port); done: up(&usb_address0_sem); }
static void usb_hub_port_connect_change(USB_HUB_T *hubstate, USB_DEV_T *hub, int port, USB_PORT_STATUS_T *portsts) { USB_DEV_T *dev; uint16_t portstatus; // portchange; uint32_t delay = HUB_SHORT_RESET_TIME; int i; portstatus = portsts->wPortStatus; //portchange = portsts->wPortChange; //USB_info("usb_hub_port_connect_change - port %d, portstatus %x, change %x, %s\n", port + 1, portstatus, // portchange, portstatus & (1 << USB_PORT_FEAT_LOWSPEED) ? "1.5 Mb/s" : "12 Mb/s"); /* Clear the connection change status */ usb_clear_port_feature(hub, port + 1, USB_PORT_FEAT_C_CONNECTION); /* Disconnect any existing devices under this port */ if(hub->children[port]) usbh_disconnect_device(&hub->children[port]); /* Return now if nothing is connected */ if(!(portstatus & USB_PORT_STAT_CONNECTION)) { if(portstatus & USB_PORT_STAT_ENABLE) usb_hub_port_disable(hub, port); return; } if(portstatus & USB_PORT_STAT_LOW_SPEED) { usbh_mdelay(400); delay = HUB_LONG_RESET_TIME; } for(i = 0; i < HUB_PROBE_TRIES; i++) { /* Allocate a new device struct */ dev = usbh_alloc_device(hub, hub->bus); if(!dev) { USB_error("Error - couldn't allocate usb_device\n"); break; } dev->hub_port = port; hub->children[port] = dev; if(usb_hub_port_reset(hub, port, dev, delay)) { usbh_free_device(dev); break; } /* Find a new device ID for it */ usbh_connect_device(dev); USB_debug("USB new device connect, assigned device number %d\n", dev->devnum); /* Run it through the hoops (find a driver, etc) */ if(usbh_settle_new_device(dev) == 0) return; // OK. /* Free the configuration if there was an error */ usbh_free_device(dev); /* Switch to a long reset time */ delay = HUB_LONG_RESET_TIME; } hub->children[port] = NULL; usb_hub_port_disable(hub, port); }
static void usb_hub_port_connect_change(struct usb_hub *hubstate, int port, u16 portstatus, u16 portchange) { struct usb_device *hub = hubstate->dev; struct usb_device *dev; unsigned int delay = HUB_SHORT_RESET_TIME; int i; dbg("port %d, portstatus %x, change %x, %s", port + 1, portstatus, portchange, portspeed (portstatus)); /* Clear the connection change status */ usb_clear_port_feature(hub, port + 1, USB_PORT_FEAT_C_CONNECTION); /* Disconnect any existing devices under this port */ if (hub->children[port]) usb_disconnect(&hub->children[port]); /* Return now if nothing is connected */ if (!(portstatus & USB_PORT_STAT_CONNECTION)) { if (portstatus & USB_PORT_STAT_ENABLE) usb_hub_port_disable(hub, port); return; } if (usb_hub_port_debounce(hub, port)) { err("connect-debounce failed, port %d disabled", port+1); usb_hub_port_disable(hub, port); return; } down(&usb_address0_sem); for (i = 0; i < HUB_PROBE_TRIES; i++) { struct usb_device *pdev; int len; /* Allocate a new device struct */ dev = usb_alloc_dev(hub, hub->bus); if (!dev) { err("couldn't allocate usb_device"); break; } hub->children[port] = dev; /* add by Levis for wakeup BP */ int begin = 0; #ifdef CONFIG_ARCH_EZXBASE set_GPIO_mode(GPIO_IN | GPIO_BP_RDY); if(!GPIO_is_high(GPIO_BP_RDY)) { if(GPIO_is_high(GPIO_AP_RDY )) { GPCR(GPIO_AP_RDY ) = GPIO_bit(GPIO_AP_RDY ); udelay(WAKE_UP_BP_UDELAY); GPSR(GPIO_AP_RDY ) = GPIO_bit(GPIO_AP_RDY ); }else { GPSR(GPIO_AP_RDY ) = GPIO_bit(GPIO_AP_RDY ); udelay(WAKE_UP_BP_UDELAY); GPCR(GPIO_AP_RDY ) = GPIO_bit(GPIO_AP_RDY ); } begin = jiffies; while(!GPIO_is_high(GPIO_BP_RDY) && (jiffies < (begin+HZ))) ; if(!GPIO_is_high(GPIO_BP_RDY)) { printk("%s: Wakeup BP timeout! BP is still in sleep state!\n", __FUNCTION__); } } #else set_GPIO_mode(GPIO_IN | 41); if(GPIO_is_high(41)) { if(GPIO_is_high(GPIO_MCU_INT_SW)) GPCR(GPIO_MCU_INT_SW) = GPIO_bit(GPIO_MCU_INT_SW); else { GPSR(GPIO_MCU_INT_SW) = GPIO_bit(GPIO_MCU_INT_SW); } begin = jiffies; while(GPIO_is_high(41) && (jiffies < (begin+HZ))) printk("%s: waitting for BP active!\n", __FUNCTION__); if(GPIO_is_high(GPIO_MCU_INT_SW)) GPCR(GPIO_MCU_INT_SW) = GPIO_bit(GPIO_MCU_INT_SW); else { GPSR(GPIO_MCU_INT_SW) = GPIO_bit(GPIO_MCU_INT_SW); } } #endif /* end Levis */ /* Reset the device */ if (usb_hub_port_reset(hub, port, dev, delay)) { usb_free_dev(dev); break; } /* Find a new device ID for it */ usb_connect(dev); /* Set up TT records, if needed */ if (hub->tt) { dev->tt = hub->tt; dev->ttport = hub->ttport; } else if (dev->speed != USB_SPEED_HIGH && hub->speed == USB_SPEED_HIGH) { dev->tt = &hubstate->tt; dev->ttport = port + 1; } /* Save readable and stable topology id, distinguishing * devices by location for diagnostics, tools, etc. The * string is a path along hub ports, from the root. Each * device's id will be stable until USB is re-cabled, and * hubs are often labeled with these port numbers. * * Initial size: ".NN" times five hubs + NUL = 16 bytes max * (quite rare, since most hubs have 4-6 ports). */ pdev = dev->parent; if (pdev->devpath [0] != '0') /* parent not root? */ len = snprintf (dev->devpath, sizeof dev->devpath, "%s.%d", pdev->devpath, port + 1); /* root == "0", root port 2 == "2", port 3 that hub "2.3" */ else len = snprintf (dev->devpath, sizeof dev->devpath, "%d", port + 1); if (len == sizeof dev->devpath) warn ("devpath size! usb/%03d/%03d path %s", dev->bus->busnum, dev->devnum, dev->devpath); info("new USB device %s-%s, assigned address %d", dev->bus->bus_name, dev->devpath, dev->devnum); /* Run it through the hoops (find a driver, etc) */ if (!usb_new_device(dev)) goto done; /* Free the configuration if there was an error */ usb_free_dev(dev); /* Switch to a long reset time */ delay = HUB_LONG_RESET_TIME; } hub->children[port] = NULL; usb_hub_port_disable(hub, port); done: up(&usb_address0_sem); }