int ehci_power_control(struct device *dev, int force_enable,const char *buf) { struct platform_device *pdev; if(dev ) pdev = to_platform_device(dev); else pdev = &s5p_device_ehci; struct s5p_ehci_platdata *pdata = pdev->dev.platform_data; struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev); struct usb_hcd *hcd = s5p_ehci->hcd; int power_on; int irq; int retval; if(dev){ if (sscanf(buf, "%d", &power_on) != 1) return -EINVAL; device_lock(dev); pm_runtime_get_sync(dev); }else{ power_on = force_enable; } if (!power_on && s5p_ehci->power_on) { printk(KERN_DEBUG "%s: EHCI turns off\n", __func__); s5p_ehci->power_on = 0; usb_remove_hcd(hcd); if (pdata && pdata->phy_exit) pdata->phy_exit(pdev, S5P_USB_PHY_HOST); } else if (power_on) { printk(KERN_DEBUG "%s: EHCI turns on\n", __func__); if (s5p_ehci->power_on) { usb_remove_hcd(hcd); } if (pdata && pdata->phy_init) pdata->phy_init(pdev, S5P_USB_PHY_HOST); s5p_ehci_configurate(hcd); irq = platform_get_irq(pdev, 0); retval = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); if (retval < 0) { dev_err(dev, "Power On Fail\n"); goto exit; } s5p_ehci->power_on = 1; } exit: if(dev){ pm_runtime_put_sync(dev); device_unlock(dev); } return 0; }
static int s5p_ehci_resume(struct device *dev) { struct platform_device *pdev = to_platform_device(dev); struct s5p_ehci_platdata *pdata = pdev->dev.platform_data; struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev); struct usb_hcd *hcd = s5p_ehci->hcd; struct ehci_hcd *ehci = hcd_to_ehci(hcd); clk_enable(s5p_ehci->clk); pm_runtime_resume(&pdev->dev); if (pdata->phy_init) pdata->phy_init(pdev, S5P_USB_PHY_HOST); s5p_ehci_configurate(hcd); if (time_before(jiffies, ehci->next_statechange)) msleep(10); /* Mark hardware accessible again as we are out of D3 state by now */ set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) { int mask = INTR_MASK; if (!hcd->self.root_hub->do_remote_wakeup) mask &= ~STS_PCD; ehci_writel(ehci, mask, &ehci->regs->intr_enable); ehci_readl(ehci, &ehci->regs->intr_enable); return 0; } ehci_dbg(ehci, "lost power, restarting\n"); usb_root_hub_lost_power(hcd->self.root_hub); (void) ehci_halt(ehci); (void) ehci_reset(ehci); /* emptying the schedule aborts any urbs */ spin_lock_irq(&ehci->lock); if (ehci->reclaim) end_unlink_async(ehci); ehci_work(ehci); spin_unlock_irq(&ehci->lock); ehci_writel(ehci, ehci->command, &ehci->regs->command); ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag); ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */ /* here we "know" root ports should always stay powered */ ehci_port_power(ehci, 1); hcd->state = HC_STATE_SUSPENDED; return 0; }
static int s5p_ehci_runtime_resume(struct device *dev) { struct platform_device *pdev = to_platform_device(dev); struct s5p_ehci_platdata *pdata = pdev->dev.platform_data; struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev); struct usb_hcd *hcd = s5p_ehci->hcd; struct ehci_hcd *ehci = hcd_to_ehci(hcd); int rc = 0; if (dev->power.is_suspended) return 0; /* platform device isn't suspended */ if (pdata && pdata->phy_resume) rc = pdata->phy_resume(pdev, S5P_USB_PHY_HOST); if (rc) { s5p_ehci_configurate(hcd); /* emptying the schedule aborts any urbs */ spin_lock_irq(&ehci->lock); if (ehci->reclaim) end_unlink_async(ehci); ehci_work(ehci); spin_unlock_irq(&ehci->lock); usb_root_hub_lost_power(hcd->self.root_hub); ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag); ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable); (void)ehci_readl(ehci, &ehci->regs->intr_enable); /* here we "know" root ports should always stay powered */ ehci_port_power(ehci, 1); hcd->state = HC_STATE_SUSPENDED; #if 0//def CONFIG_USB_EXYNOS_SWITCH } else { if (1) //samsung_board_rev_is_0_0()) /* the same board configuration that Mehmet DVT has */ { ehci_hub_control(ehci_to_hcd(ehci), SetPortFeature, USB_PORT_FEAT_POWER, 1, NULL, 0); /* Flush those writes */ ehci_readl(ehci, &ehci->regs->command); msleep(20); } #endif } return 0; }
static void s5p_ehci_phy_init(struct platform_device *pdev) { struct s5p_ehci_platdata *pdata = pdev->dev.platform_data; struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev); struct usb_hcd *hcd = s5p_ehci->hcd; if (pdata && pdata->phy_init) { pdata->phy_init(pdev, S5P_USB_PHY_HOST); s5p_ehci_configurate(hcd); } }
static int s5p_ehci_runtime_resume(struct device *dev) { struct platform_device *pdev = to_platform_device(dev); struct s5p_ehci_platdata *pdata = pdev->dev.platform_data; struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev); struct usb_hcd *hcd = s5p_ehci->hcd; struct ehci_hcd *ehci = hcd_to_ehci(hcd); int rc = 0; if (dev->power.is_suspended) return 0; #ifdef CONFIG_MDM_HSIC_PM request_active_lock_set(hsic_pm_dev); #endif /* platform device isn't suspended */ if (pdata && pdata->phy_resume) rc = pdata->phy_resume(pdev, S5P_USB_PHY_HOST); if (rc) { s5p_ehci_configurate(hcd); /* emptying the schedule aborts any urbs */ spin_lock_irq(&ehci->lock); if (ehci->reclaim) end_unlink_async(ehci); ehci_work(ehci); spin_unlock_irq(&ehci->lock); usb_root_hub_lost_power(hcd->self.root_hub); ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag); ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable); (void)ehci_readl(ehci, &ehci->regs->intr_enable); /* here we "know" root ports should always stay powered */ ehci_port_power(ehci, 1); hcd->state = HC_STATE_SUSPENDED; #ifdef CONFIG_MDM_HSIC_PM set_host_stat(hsic_pm_dev, POWER_ON); wait_dev_pwr_stat(hsic_pm_dev, POWER_ON); #endif #if defined(CONFIG_LINK_DEVICE_HSIC) || defined(CONFIG_LINK_DEVICE_USB) \ || defined(CONFIG_MDM_HSIC_PM) s5p_wait_for_cp_resume(pdev, hcd); #endif } return 0; }
static void s5p_ehci_phy_init(struct platform_device *pdev) { struct usb_hcd *hcd = platform_get_drvdata(pdev); struct s5p_ehci_hcd *s5p_ehci = to_s5p_ehci(hcd); if (s5p_ehci->phy) { usb_phy_init(s5p_ehci->phy); s5p_ehci->post_lpa_resume = 0; } else if (s5p_ehci->pdata->phy_init) { s5p_ehci->pdata->phy_init(pdev, USB_PHY_TYPE_HOST); } else { dev_err(&pdev->dev, "Failed to init ehci phy\n"); return; } s5p_ehci_configurate(hcd); }
static int s5p_ehci_runtime_resume(struct device *dev) { struct platform_device *pdev = to_platform_device(dev); struct s5p_ehci_platdata *pdata = pdev->dev.platform_data; struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev); struct usb_hcd *hcd = s5p_ehci->hcd; struct ehci_hcd *ehci = hcd_to_ehci(hcd); int rc = 0; if (dev->power.is_suspended) return 0; /* platform device isn't suspended */ if (pdata && pdata->phy_resume) rc = pdata->phy_resume(pdev, S5P_USB_PHY_HOST); if (rc) { s5p_ehci_configurate(hcd); /* emptying the schedule aborts any urbs */ spin_lock_irq(&ehci->lock); if (ehci->reclaim) end_unlink_async(ehci); ehci_work(ehci); spin_unlock_irq(&ehci->lock); usb_root_hub_lost_power(hcd->self.root_hub); ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag); ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable); (void)ehci_readl(ehci, &ehci->regs->intr_enable); /* here we "know" root ports should always stay powered */ ehci_port_power(ehci, 1); hcd->state = HC_STATE_SUSPENDED; } #if defined(CONFIG_LINK_DEVICE_HSIC) pr_info("%s: usage=%d, child=%d\n", __func__, atomic_read(&dev->power.usage_count), atomic_read(&dev->power.child_count)); #endif return 0; }
static int s5p_ehci_runtime_resume(struct device *dev) { struct platform_device *pdev = to_platform_device(dev); struct s5p_ehci_platdata *pdata = pdev->dev.platform_data; struct usb_hcd *hcd = platform_get_drvdata(pdev); struct s5p_ehci_hcd *s5p_ehci = to_s5p_ehci(hcd); int rc = 0; if (dev->power.is_suspended) return 0; dev_dbg(dev, "%s\n", __func__); if (s5p_ehci->phy) { struct usb_phy *phy = s5p_ehci->phy; if (s5p_ehci->post_lpa_resume) usb_phy_init(phy); pm_runtime_get_sync(phy->dev); } else if (pdata && pdata->phy_resume) { rc = pdata->phy_resume(pdev, USB_PHY_TYPE_HOST); s5p_ehci->post_lpa_resume = !!rc; } if (s5p_ehci->post_lpa_resume) s5p_ehci_configurate(hcd); ehci_resume(hcd, false); /* * REVISIT: in case of LPA bus won't be resumed, so we do it here. * Alternatively, we can try to setup HC in such a way that it starts * to sense connections. In this case, root hub will be resumed from * interrupt (ehci_irq()). */ if (s5p_ehci->post_lpa_resume) usb_hcd_resume_root_hub(hcd); s5p_ehci->post_lpa_resume = 0; return 0; }
static int s5p_ehci_runtime_resume(struct device *dev) { struct platform_device *pdev = to_platform_device(dev); struct s5p_ehci_platdata *pdata = pdev->dev.platform_data; struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev); struct usb_hcd *hcd = s5p_ehci->hcd; struct ehci_hcd *ehci = hcd_to_ehci(hcd); int rc = 0; if (dev->power.is_suspended) return 0; /* platform device isn't suspended */ if (pdata && pdata->phy_resume) rc = pdata->phy_resume(pdev, S5P_USB_PHY_HOST); if (rc) { s5p_ehci_configurate(hcd); /* emptying the schedule aborts any urbs */ spin_lock_irq(&ehci->lock); if (ehci->reclaim) end_unlink_async(ehci); ehci_work(ehci); spin_unlock_irq(&ehci->lock); usb_root_hub_lost_power(hcd->self.root_hub); ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag); ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable); (void)ehci_readl(ehci, &ehci->regs->intr_enable); /* here we "know" root ports should always stay powered */ ehci_port_power(ehci, 1); ehci->rh_state = EHCI_RH_SUSPENDED; } return 0; }
static void s5p_ehci_phy_init(struct platform_device *pdev) { struct s5p_ehci_platdata *pdata = pdev->dev.platform_data; struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev); struct usb_hcd *hcd = s5p_ehci->hcd; u32 delay_count = 0; if (pdata && pdata->phy_init) { pdata->phy_init(pdev, S5P_USB_PHY_HOST); while (!readl(hcd->regs) && delay_count < 200) { delay_count++; udelay(1); } if (delay_count) dev_info(&pdev->dev, "waiting time = %d\n", delay_count); s5p_ehci_configurate(hcd); dev_dbg(&pdev->dev, "%s : 0x%x\n", __func__, readl(INSNREG00(hcd->regs))); } }
static int __devinit s5p_ehci_probe(struct platform_device *pdev) { struct s5p_ehci_platdata *pdata; struct s5p_ehci_hcd *s5p_ehci; struct usb_hcd *hcd; struct ehci_hcd *ehci; struct resource *res; int irq; int err; pdata = pdev->dev.platform_data; if (!pdata) { dev_err(&pdev->dev, "No platform data defined\n"); return -EINVAL; } s5p_ehci = kzalloc(sizeof(struct s5p_ehci_hcd), GFP_KERNEL); if (!s5p_ehci) return -ENOMEM; s5p_ehci->dev = &pdev->dev; hcd = usb_create_hcd(&s5p_ehci_hc_driver, &pdev->dev, dev_name(&pdev->dev)); if (!hcd) { dev_err(&pdev->dev, "Unable to create HCD\n"); err = -ENOMEM; goto fail_hcd; } s5p_ehci->hcd = hcd; s5p_ehci->clk = clk_get(&pdev->dev, "usbhost"); if (IS_ERR(s5p_ehci->clk)) { dev_err(&pdev->dev, "Failed to get usbhost clock\n"); err = PTR_ERR(s5p_ehci->clk); goto fail_clk; } err = clk_enable(s5p_ehci->clk); if (err) goto fail_clken; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { dev_err(&pdev->dev, "Failed to get I/O memory\n"); err = -ENXIO; goto fail_io; } hcd->rsrc_start = res->start; hcd->rsrc_len = resource_size(res); hcd->regs = ioremap(res->start, resource_size(res)); if (!hcd->regs) { dev_err(&pdev->dev, "Failed to remap I/O memory\n"); err = -ENOMEM; goto fail_io; } irq = platform_get_irq(pdev, 0); if (!irq) { dev_err(&pdev->dev, "Failed to get IRQ\n"); err = -ENODEV; goto fail; } if (pdata->phy_init) pdata->phy_init(pdev, S5P_USB_PHY_HOST); ehci = hcd_to_ehci(hcd); ehci->caps = hcd->regs; ehci->regs = hcd->regs + HC_LENGTH(ehci, readl(&ehci->caps->hc_capbase)); s5p_ehci_configurate(hcd); dbg_hcs_params(ehci, "reset"); dbg_hcc_params(ehci, "reset"); /* cache this readonly data; minimize chip reads */ ehci->hcs_params = readl(&ehci->caps->hcs_params); err = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); if (err) { dev_err(&pdev->dev, "Failed to add USB HCD\n"); goto fail; } platform_set_drvdata(pdev, s5p_ehci); create_ehci_sys_file(ehci); s5p_ehci->power_on = 1; #if 0//def CONFIG_USB_EXYNOS_SWITCH if (1) //samsung_board_rev_is_0_0()) /* the same board configuration that Mehmet DVT has */ ehci_hub_control(ehci_to_hcd(ehci), ClearPortFeature, USB_PORT_FEAT_POWER, 1, NULL, 0); #endif #ifdef CONFIG_USB_SUSPEND pm_runtime_set_active(&pdev->dev); pm_runtime_enable(&pdev->dev); #endif return 0; fail: iounmap(hcd->regs); fail_io: clk_disable(s5p_ehci->clk); fail_clken: clk_put(s5p_ehci->clk); fail_clk: usb_put_hcd(hcd); fail_hcd: kfree(s5p_ehci); return err; }