static int usb_hub_reset(struct usb_hub *hub) { struct usb_device *dev = hub->dev; int i; DBG_HOST_HUB("### >>> Enter hub.c file --> usb_hub_reset function \n"); /* Disconnect any attached devices */ for (i = 0; i < hub->descriptor->bNbrPorts; i++) { if (dev->children[i]) usb_disconnect(&dev->children[i]); } /* Attempt to reset the hub */ if (hub->urb) usb_unlink_urb(hub->urb); else return -1; if (usb_reset_device(dev)) return -1; hub->urb->dev = dev; if (usb_submit_urb(hub->urb)) return -1; usb_hub_power_on(hub); return 0; }
static int __init_or_module arc_ehci_remove(struct device *dev) { struct ehci_hcd *ehci = dev_get_drvdata(dev); struct usb_hcd *hcd = ehci_to_hcd(ehci); struct arc_usb_config *config; config = (struct arc_usb_config *)dev->platform_data; dbg("%s dev=0x%p\n", __FUNCTION__, dev); if (HCD_IS_RUNNING(hcd->state)) hcd->state = USB_STATE_QUIESCING; usb_disconnect(&hcd->self.root_hub); hcd->driver->stop(hcd); hcd_buffer_destroy(hcd); usb_deregister_bus(&hcd->self); free_irq(hcd->irq, hcd); usb_put_hcd(hcd); /* * do platform specific un-initialization: * release iomux pins, etc. */ config->platform_uninit(); return 0; }
/** * usb_hcd_omap_remove - shutdown processing for OMAP-based HCDs * @dev: USB Host Controller being removed * Context: !in_interrupt() * * Reverses the effect of usb_hcd_omap_probe(), first invoking * the HCD's stop() method. It is always called from a thread * context, normally "rmmod", "apmd", or something similar. * */ void usb_hcd_omap_remove (struct usb_hcd *hcd, struct platform_device *pdev) { dev_info(&pdev->dev, "remove: state %x\n", hcd->state); if (in_interrupt ()) BUG (); hcd->state = USB_STATE_QUIESCING; dev_dbg(&pdev->dev, "roothub graceful disconnect\n"); usb_disconnect (&hcd->self.root_hub); hcd->driver->stop (hcd); hcd_buffer_destroy (hcd); hcd->state = USB_STATE_HALT; if (machine_is_omap_osk()) omap_free_gpio(9); free_irq (hcd->irq, hcd); usb_deregister_bus (&hcd->self); omap_stop_hc(pdev); release_mem_region(pdev->resource[0].start, pdev->resource[0].end - pdev->resource[0].start + 1); }
/** * usb_hcd_pci_remove - shutdown processing for PCI-based HCDs * @dev: USB Host Controller being removed * Context: !in_interrupt() * * Reverses the effect of usb_hcd_pci_probe(), first invoking * the HCD's stop() method. It is always called from a thread * context, normally "rmmod", "apmd", or something similar. * * Store this function in the HCD's struct pci_driver as remove(). */ void usb_hcd_pci_remove (struct pci_dev *dev) { struct usb_hcd *hcd; hcd = pci_get_drvdata(dev); if (!hcd) return; dev_info (hcd->self.controller, "remove, state %x\n", hcd->state); if (in_interrupt ()) BUG (); if (HCD_IS_RUNNING (hcd->state)) hcd->state = USB_STATE_QUIESCING; dev_dbg (hcd->self.controller, "roothub graceful disconnect\n"); usb_disconnect (&hcd->self.root_hub); hcd->driver->stop (hcd); hcd_buffer_destroy (hcd); hcd->state = USB_STATE_HALT; pci_set_drvdata(dev, NULL); free_irq (hcd->irq, hcd); if (hcd->driver->flags & HCD_MEMORY) { iounmap (hcd->regs); release_mem_region (pci_resource_start (dev, 0), pci_resource_len (dev, 0)); } else { release_region (pci_resource_start (dev, hcd->region), pci_resource_len (dev, hcd->region)); } usb_deregister_bus (&hcd->self); }
static int hub_reset(struct usb_hub *hub) { struct usb_device *dev = interface_to_usbdev(hub->intf); int i; /* Disconnect any attached devices */ for (i = 0; i < hub->descriptor->bNbrPorts; i++) { if (dev->children[i]) usb_disconnect(&dev->children[i]); } /* Attempt to reset the hub */ if (hub->urb) usb_unlink_urb(hub->urb); else return -1; if (usb_reset_device(dev)) return -1; hub->urb->dev = dev; if (usb_submit_urb(hub->urb, GFP_KERNEL)) return -1; hub_power_on(hub); return 0; }
/***************************************************************** * * Function Name: hc_release_hci * * This function De-allocate all resources * * Input: hci = data structure for the host controller * * Return value : 0 * *****************************************************************/ static void hc_release_hci (hci_t * hci) { hcipriv_t *hp = &hci->hp; DBGFUNC ("Enter hc_release_hci\n"); /* disconnect all devices */ if (hci->bus->root_hub) usb_disconnect (&hci->bus->root_hub); hc_reset (hci); if (hp->tl) kfree (hp->tl); if (hp->hcport > 0) { release_region (hp->hcport, 2); hp->hcport = 0; } if (hp->irq >= 0) { free_irq (hp->irq, hci); hp->irq = -1; } usb_deregister_bus (hci->bus); usb_put_bus (hci->bus); list_del_init (&hci->hci_hcd_list); kfree (hci); }
/** * usb_hcd_omap_remove - shutdown processing for OMAP-based HCDs * @dev: USB Host Controller being removed * Context: !in_interrupt() * * Reverses the effect of usb_hcd_omap_probe(), first invoking * the HCD's stop() method. It is always called from a thread * context, normally "rmmod", "apmd", or something similar. * */ void usb_hcd_omap_remove (struct usb_hcd *hcd, struct omap_dev *dev) { struct usb_device *hub; void *base; info ("remove: %s, state %x", hcd->self.bus_name, hcd->state); if (in_interrupt ()) BUG (); hub = hcd->self.root_hub; hcd->state = USB_STATE_QUIESCING; dbg ("%s: roothub graceful disconnect", hcd->self.bus_name); usb_disconnect (&hub); hcd->driver->stop (hcd); hcd_buffer_destroy (hcd); hcd->state = USB_STATE_HALT; free_irq (hcd->irq, hcd); usb_deregister_bus (&hcd->self); base = hcd->regs; hcd->driver->hcd_free (hcd); omap_stop_hc(dev); release_mem_region(dev->res.start, dev->res.end - dev->res.start + 1); }
/** * usb_hcd_ppc_soc_remove - shutdown processing for On-Chip HCDs * @pdev: USB Host Controller being removed * Context: !in_interrupt() * * Reverses the effect of usb_hcd_ppc_soc_probe(), first invoking * the HCD's stop() method. It is always called from a thread * context, normally "rmmod", "apmd", or something similar. * */ static void usb_hcd_ppc_soc_remove(struct usb_hcd *hcd, struct platform_device *pdev) { struct resource *res; pr_debug(__FILE__ ": remove: %s, state %x\n", hcd->self.bus_name, hcd->state); if (in_interrupt()) BUG(); hcd->state = USB_STATE_QUIESCING; pr_debug("%s: roothub graceful disconnect\n", hcd->self.bus_name); usb_disconnect(&hcd->self.root_hub); hcd->driver->stop(hcd); hcd->state = USB_STATE_HALT; free_irq(hcd->irq, hcd); hcd_buffer_destroy(hcd); usb_deregister_bus(&hcd->self); iounmap(hcd->regs); kfree(hcd); pr_debug("stopping PPC-SOC USB Controller\n"); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); release_mem_region(res->start, res->end - res->start + 1); }
static void hc_restart (ohci_t *ohci) { int temp; int i; if (ohci->pci_latency) pci_write_config_byte (ohci->ohci_dev, PCI_LATENCY_TIMER, ohci->pci_latency); ohci->disabled = 1; ohci->sleeping = 0; if (ohci->bus->root_hub) usb_disconnect (&ohci->bus->root_hub); /* empty the interrupt branches */ for (i = 0; i < NUM_INTS; i++) ohci->ohci_int_load[i] = 0; for (i = 0; i < NUM_INTS; i++) ohci->hcca->int_table[i] = 0; /* no EDs to remove */ ohci->ed_rm_list [0] = NULL; ohci->ed_rm_list [1] = NULL; /* empty control and bulk lists */ ohci->ed_isotail = NULL; ohci->ed_controltail = NULL; ohci->ed_bulktail = NULL; if ((temp = hc_reset (ohci)) < 0 || (temp = hc_start (ohci)) < 0) { err ("can't restart usb-%s, %d", ohci->ohci_dev->slot_name, temp); } else dbg ("restart usb-%s completed", ohci->ohci_dev->slot_name); }
/** * usb_hcd_pxa27x_remove - shutdown processing for pxa27x-based HCDs * @dev: USB Host Controller being removed * Context: !in_interrupt() * * Reverses the effect of usb_hcd_pxa27x_probe(), first invoking * the HCD's stop() method. It is always called from a thread * context, normally "rmmod", "apmd", or something similar. * */ void usb_hcd_pxa27x_remove (struct usb_hcd *hcd, struct platform_device *dev) { void *base; pr_debug ("remove: %s, state %x", hcd->self.bus_name, hcd->state); if (in_interrupt ()) BUG (); hcd->state = USB_STATE_QUIESCING; pr_debug ("%s: roothub graceful disconnect", hcd->self.bus_name); usb_disconnect (&hcd->self.root_hub); hcd->driver->stop (hcd); hcd->state = USB_STATE_HALT; free_irq (hcd->irq, hcd); hcd_buffer_destroy (hcd); usb_deregister_bus (&hcd->self); base = hcd->regs; hcd->driver->hcd_free (hcd); pxa27x_stop_hc(dev); release_mem_region(dev->resource[0].start, dev->resource[0].end - dev->resource[0].start + 1); }
static int svdm_enter_mode(int port, uint32_t *payload) { int rv = 0; /* will generate a NAK */ /* SID & mode request is valid */ if ((PD_VDO_VID(payload[0]) == USB_SID_DISPLAYPORT) && (PD_VDO_OPOS(payload[0]) == OPOS_DP)) { alt_mode[PD_AMODE_DISPLAYPORT] = OPOS_DP; rv = 1; pd_log_event(PD_EVENT_VIDEO_DP_MODE, 0, 1, NULL); } else if ((PD_VDO_VID(payload[0]) == USB_VID_GOOGLE) && (PD_VDO_OPOS(payload[0]) == OPOS_GFU)) { alt_mode[PD_AMODE_GOOGLE] = OPOS_GFU; rv = 1; } if (rv) /* * If we failed initial mode entry we'll have enumerated the USB * Billboard class. If so we should disconnect. */ usb_disconnect(); return rv; }
/** * usb_remove_hcd - shutdown processing for generic HCDs * @hcd: the usb_hcd structure to remove * Context: !in_interrupt() * * Disconnects the root hub, then reverses the effects of usb_add_hcd(), * invoking the HCD's stop() method. */ void mtk_usb_remove_hcd(struct usb_hcd *hcd) { dev_info(hcd->self.controller, "remove, state %x\n", hcd->state); if (HC_IS_RUNNING (hcd->state)) hcd->state = HC_STATE_QUIESCING; dev_dbg(hcd->self.controller, "roothub graceful disconnect\n"); #if 0 spin_lock_irq (&hcd_root_hub_lock); hcd->rh_registered = 0; spin_unlock_irq (&hcd_root_hub_lock); #endif #if 0 //#ifdef CONFIG_USB_SUSPEND cancel_work_sync(&hcd->wakeup_work); #endif #if 0 sysfs_remove_group(&hcd->self.root_hub->dev.kobj, &usb_bus_attr_group); mutex_lock(&usb_bus_list_lock); usb_disconnect(&hcd->self.root_hub); mutex_unlock(&usb_bus_list_lock); #endif hcd->driver->stop(hcd); hcd->state = HC_STATE_HALT; #if 0 hcd->poll_rh = 0; del_timer_sync(&hcd->rh_timer); #endif if (hcd->irq >= 0) free_irq(hcd->irq, hcd); #if 0 usb_deregister_bus(&hcd->self); #endif hcd_buffer_destroy(hcd); }
/** * usb_hcd_ppc_soc_remove - shutdown processing for On-Chip HCDs * @pdev: USB Host Controller being removed * Context: !in_interrupt() * * Reverses the effect of usb_hcd_ppc_soc_probe(). * It is always called from a thread * context, normally "rmmod", "apmd", or something similar. * */ static void usb_hcd_ppc_soc_remove(struct platform_device *pdev) { struct usb_hcd *hcd; struct resource *res; hcd = dev_get_drvdata(&pdev->dev); if (!hcd) return; if (in_interrupt()) BUG(); if (HCD_IS_RUNNING(hcd->state)) hcd->state = USB_STATE_QUIESCING; usb_disconnect(&hcd->self.root_hub); hcd->driver->stop(hcd); del_timer_sync(&hcd->rh_timer); hcd_buffer_destroy(hcd); hcd->state = USB_STATE_HALT; dev_set_drvdata(&pdev->dev, NULL); free_irq(hcd->irq, hcd); iounmap(hcd->regs); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (res) { release_mem_region(res->start, res->end - res->start + 1); } usb_deregister_bus (&hcd->self); pr_debug("Removed PPC-SOC EHCI USB Controller\n"); }
static int usb_hub_reset(struct usb_hub *hub) { struct usb_device *dev = hub->dev; int i; /* Disconnect any attached devices */ for (i = 0; i < hub->nports; i++) { if (dev->children[i]) usb_disconnect(&dev->children[i]); } /* Attempt to reset the hub */ if (hub->urb) usb_unlink_urb(hub->urb); else return -1; if (usb_reset_device(dev)) return -1; if (usb_submit_urb(hub->urb)) return -1; usb_hub_power_on(hub); return 0; }
static void ush_hsic_port_disable(struct pci_dev *pdev) { printk(KERN_ERR "%s---->\n", __func__); #if 1 if (hsic.modem_dev) { struct usb_device *hdev; dev_dbg(&pci_dev->dev, "%s----> disconnect modem\n", __func__); hdev = hsic.modem_dev->parent; usb_disable_autosuspend(hsic.modem_dev); usb_disable_autosuspend(hsic.rh_dev); if (hdev->children[HSIC_USH_PORT - 1] == hsic.modem_dev) { printk(KERN_ERR "%s----> usb disconnect\n", __func__); usb_disconnect(&hsic.modem_dev); hdev->children[HSIC_USH_PORT - 1] = NULL; } } #endif if (hsic.rh_dev) { dev_dbg(&pci_dev->dev, "%s----> disable port\n", __func__); printk(KERN_ERR "%s----> disable PP\n", __func__); clear_port_feature(hsic.rh_dev, HSIC_USH_PORT, USB_PORT_FEAT_POWER); } hsic.hsic_stopped = 1; hsic_enable = 0; }
void DFU_transferComplete(CONTROL_TRANSFER *control) { if ((control->setup.bmRequestType & 0x7F) == 0x21) { switch(control->setup.bRequest) { case DFU_GETSTATUS: { current_state = DFU_status.bState; printf("new state is %d\n", current_state); if (current_state == dfuMANIFESTWAITRESET) { usb_disconnect(); printf("MANIFEST COMPLETE, usb disconnected\n"); } break; } case DFU_DNLOAD: { if (control->setup.wLength > 0) { printf("WRITE %p\n", flash_p); setleds(((uint32_t) (flash_p - 0x4000)) >> 15); // we must pass DFU_BLOCK_SIZE to write_flash for some reason, it does not flash if we pass a smaller length int r = write_flash((void *) flash_p, (char *) block_buffer, DFU_BLOCK_SIZE); // int r; // for (r = 0; r < control->setup.wLength; r++) // { // printf("0x%x ", flash_p[r]); // if ((r & 31) == 31) // printf("\n"); // } if (r == 0) { flash_p += control->setup.wLength; DFU_status.bState = dfuDNLOADIDLE; } else { printf("write flash error %d\n", r); DFU_status.bStatus = errPROG; DFU_status.bState = dfuERROR; } } else { current_state = dfuMANIFESTSYNC; DFU_status.bState = dfuMANIFESTWAITRESET; } break; } case DFU_UPLOAD: DFU_status.bState = dfuUPLOADIDLE; flash_p += control->setup.wLength; break; }
static void usb_set_mode(struct obex_server *server, const char *mode) { DBG("%s", mode); if (g_str_equal(mode, "ovi_suite") == TRUE) usb_connect(server); else if (g_str_equal(mode, "USB disconnected") == TRUE) usb_disconnect(server); }
void start_dfu() { DFU_init(); usb_init(); usb_connect(); while (DFU_complete() == 0) usb_task(); usb_disconnect(); }
/* * This functions performs USB disconnect operations wrt Diag synchronously. * It doesn't translate to actual USB disconnect. This is used when Diag * switches logging from USB mode and want to mimic USB disconnect. */ void diag_usb_disconnect_all(void) { int i = 0; struct diag_usb_info *usb_info = NULL; for (i = 0; i < NUM_DIAG_USB_DEV; i++) { usb_info = &diag_usb[i]; if (!usb_info->enabled) continue; usb_disconnect(usb_info); } }
/*============================================================================*/ bool usb_handshake(struct bldr_command_handler *handler) { uint32 enum_tmo = CFG_USB_ENUM_TIMEOUT_EN ? USB_ENUM_TIMEOUT : 0; uint32 handshake_tmo = CFG_USB_HANDSHAKE_TIMEOUT_EN ? USB_SYNC_TIME : 0; bool result = FALSE; bool force_download = FALSE; platform_vusb_on(); force_download = platform_com_wait_forever_check(); if (TRUE == force_download) { enum_tmo = 0; handshake_tmo = 0; } else if (!usb_cable_in()) { return FALSE; } print("%s USB enum timeout (%s), handshake timeout(%s)\n", MOD, enum_tmo ? "Yes" : "No", handshake_tmo ? "Yes" : "No"); usbdl_init(); udelay(1000); usb_disconnect(); if (usb_connect(enum_tmo) == FALSE) { print("%s USB enum timeout!\n", MOD); goto end; } udelay(1000); if (FALSE == usb_handshake_handler(handler, handshake_tmo)) { goto end; } result = TRUE; if (FALSE == usb_port_down(USB_PORT_DOWN_TIME)) { print("%s USB port down timeout!\n", MOD); } end: usb_service_offline(); #if CFG_USBIF_COMPLIANCE /* USB compliance test: 100mA charging current when USB is unconfigured. */ platform_set_chrg_cur(70); #endif return result; }
static gboolean usb_watchdog(GIOChannel *io, GIOCondition cond, void *user_data) { struct obex_server *server = user_data; usb_watch = 0; usb_disconnect(server); if ((cond & G_IO_NVAL) == FALSE) usb_reconnecting = g_idle_add(usb_reconnect, server); return FALSE; }
void usb_release(void) { /* signal disconnect to host */ usb_disconnect(); /* disable interrupt handlers */ task_disable_irq(GC_IRQNUM_USB0_USBINTR); /* disable clocks */ clock_enable_module(MODULE_USB, 0); /* TODO: pin-mux */ /* USB is off, so sleep whenever */ enable_sleep(SLEEP_MASK_USB_DEVICE); }
static void usb_hub_disconnect(struct usb_device *dev) { struct usb_device *parent = dev->parent; int i; /* Find the device pointer to disconnect */ if (parent) { for (i = 0; i < parent->maxchild; i++) { if (parent->children[i] == dev) { usb_disconnect(&parent->children[i]); return; } } } err("cannot disconnect hub %d", dev->devnum); }
static int pxau2h_ehci_remove(struct platform_device *pdev) { struct usb_hcd *hcd = platform_get_drvdata(pdev); if (HC_IS_RUNNING(hcd->state)) hcd->state = HC_STATE_QUIESCING; usb_disconnect(&hcd->self.root_hub); hcd->driver->stop(hcd); usb_remove_hcd(hcd); iounmap(hcd->regs); iounmap((void *)info->phybase); release_mem_region(hcd->rsrc_start, hcd->rsrc_len); usb_put_hcd(hcd); return 0; }
static gboolean handle_signal(DBusConnection *connection, DBusMessage *message, void *user_data) { struct obex_server *server = user_data; const char *state; dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &state, DBUS_TYPE_INVALID); if (g_str_equal(state, "ovi_suite") == TRUE) usb_connect(server); else if (g_str_equal(state, "USB disconnected") == TRUE) usb_disconnect(server); return TRUE; }
static void usb_hub_disconnect(struct usb_device *dev) { struct usb_device *parent = dev->parent; int i; DBG_HOST_HUB("### >>> Enter hub.c file --> usb_hub_disconnect function \n"); /* Find the device pointer to disconnect */ if (parent) { for (i = 0; i < parent->maxchild; i++) { if (parent->children[i] == dev) { usb_disconnect(&parent->children[i]); return; } } } err("cannot disconnect hub %d", dev->devnum); }
void usb_release(void) { /* signal disconnect to host */ usb_disconnect(); /* disable interrupt handlers */ task_disable_irq(GC_IRQNUM_USB0_USBINTR); /* Deactivate the PHY */ GR_USB_GGPIO = GGPIO_WRITE(USB_CUSTOM_CFG_REG, 0); /* disable clocks */ clock_enable_module(MODULE_USB, 0); /* TODO: pin-mux */ /* USB is off, so sleep whenever */ enable_sleep(SLEEP_MASK_USB_DEVICE); }
/** * usb_hcd_pci_remove - shutdown processing for PCI-based HCDs * @dev: USB Host Controller being removed * Context: !in_interrupt() * * Reverses the effect of usb_hcd_pci_probe(), first invoking * the HCD's stop() method. It is always called from a thread * context, normally "rmmod", "apmd", or something similar. * * Store this function in the HCD's struct pci_driver as remove(). */ void usb_hcd_pci_remove (struct pci_dev *dev) { struct usb_hcd *hcd; struct usb_device *hub; hcd = pci_get_drvdata(dev); if (!hcd) return; dev_info (hcd->controller, "remove, state %x\n", hcd->state); if (in_interrupt ()) BUG (); hub = hcd->self.root_hub; hcd->state = USB_STATE_QUIESCING; dev_dbg (hcd->controller, "roothub graceful disconnect\n"); usb_disconnect (&hub); hcd->driver->stop (hcd); hcd_buffer_destroy (hcd); hcd->state = USB_STATE_HALT; pci_set_drvdata (dev, 0); free_irq (hcd->irq, hcd); if (hcd->driver->flags & HCD_MEMORY) { iounmap (hcd->regs); release_mem_region (pci_resource_start (dev, 0), pci_resource_len (dev, 0)); } else { release_region (pci_resource_start (dev, hcd->region), pci_resource_len (dev, hcd->region)); } usb_deregister_bus (&hcd->self); if (atomic_read (&hcd->self.refcnt) != 1) { dev_warn (hcd->controller, "dangling refs (%d) to bus %d!\n", atomic_read (&hcd->self.refcnt) - 1, hcd->self.busnum); } hcd->driver->hcd_free (hcd); }
void usb_hcd_superh_remove(struct usb_hcd *hcd, struct platform_device *dev) { pr_debug("remove: %s, state %x", hcd->self.bus_name, hcd->state); if (in_interrupt()) BUG(); hcd->state = USB_STATE_QUIESCING; pr_debug("%s: roothub graceful disconnect", hcd->self.bus_name); usb_disconnect(&hcd->self.root_hub); hcd->driver->stop(hcd); hcd->state = USB_STATE_HALT; free_irq(hcd->irq, hcd); hcd_buffer_destroy(hcd); usb_deregister_bus(&hcd->self); superh_stop_hc(dev); release_mem_region((unsigned long)hcd->regs, sizeof(struct ohci_regs)); }
int main(){ uint32_t Old_timer = 0; // RCC clocking: 8MHz oscillator -> 72MHz system rcc_clock_setup_in_hse_8mhz_out_72mhz(); GPIO_init(); usb_disconnect(); // turn off USB while initializing all steppers_init(); // USB usbd_dev = USB_init(); // SysTick is a system timer with 1ms period SysTick_init(); // wait a little and then turn on USB pullup // for (i = 0; i < 0x800000; i++) // __asm__("nop"); usb_connect(); // turn on USB while(1){ usbd_poll(usbd_dev); if(usbdatalen){ // there's something in USB buffer usbdatalen = parce_incoming_buf(usbdatabuf, usbdatalen); } //check_and_parce_UART(USART1); // also check data in UART buffers if(Timer - Old_timer > 999){ // one-second cycle Old_timer += 1000; }else if(Timer < Old_timer){ // Timer overflow Old_timer = 0; } } }