static int ehci_platform_probe(struct platform_device *dev) { struct usb_hcd *hcd; struct resource *res_mem; struct usb_ehci_pdata *pdata = dev_get_platdata(&dev->dev); struct ehci_platform_priv *priv; struct ehci_hcd *ehci; int err, irq, phy_num, clk = 0; if (usb_disabled()) return -ENODEV; /* * Use reasonable defaults so platforms don't have to provide these * with DT probing on ARM. */ if (!pdata) pdata = &ehci_platform_defaults; err = dma_coerce_mask_and_coherent(&dev->dev, pdata->dma_mask_64 ? DMA_BIT_MASK(64) : DMA_BIT_MASK(32)); if (err) return err; irq = platform_get_irq(dev, 0); if (irq < 0) { dev_err(&dev->dev, "no irq provided"); return irq; } hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev, dev_name(&dev->dev)); if (!hcd) return -ENOMEM; platform_set_drvdata(dev, hcd); dev->dev.platform_data = pdata; priv = hcd_to_ehci_priv(hcd); ehci = hcd_to_ehci(hcd); if (pdata == &ehci_platform_defaults && dev->dev.of_node) { if (of_property_read_bool(dev->dev.of_node, "big-endian-regs")) ehci->big_endian_mmio = 1; if (of_property_read_bool(dev->dev.of_node, "big-endian-desc")) ehci->big_endian_desc = 1; if (of_property_read_bool(dev->dev.of_node, "big-endian")) ehci->big_endian_mmio = ehci->big_endian_desc = 1; if (of_property_read_bool(dev->dev.of_node, "needs-reset-on-resume")) priv->reset_on_resume = true; if (of_property_read_bool(dev->dev.of_node, "has-transaction-translator")) hcd->has_tt = 1; priv->num_phys = of_count_phandle_with_args(dev->dev.of_node, "phys", "#phy-cells"); if (priv->num_phys > 0) { priv->phys = devm_kcalloc(&dev->dev, priv->num_phys, sizeof(struct phy *), GFP_KERNEL); if (!priv->phys) return -ENOMEM; } else priv->num_phys = 0; for (phy_num = 0; phy_num < priv->num_phys; phy_num++) { priv->phys[phy_num] = devm_of_phy_get_by_index( &dev->dev, dev->dev.of_node, phy_num); if (IS_ERR(priv->phys[phy_num])) { err = PTR_ERR(priv->phys[phy_num]); goto err_put_hcd; } } for (clk = 0; clk < EHCI_MAX_CLKS; clk++) { priv->clks[clk] = of_clk_get(dev->dev.of_node, clk); if (IS_ERR(priv->clks[clk])) { err = PTR_ERR(priv->clks[clk]); if (err == -EPROBE_DEFER) goto err_put_clks; priv->clks[clk] = NULL; break; } } } priv->rst = devm_reset_control_get_optional(&dev->dev, NULL); if (IS_ERR(priv->rst)) { err = PTR_ERR(priv->rst); if (err == -EPROBE_DEFER) goto err_put_clks; priv->rst = NULL; } else { err = reset_control_deassert(priv->rst); if (err) goto err_put_clks; } if (pdata->big_endian_desc) ehci->big_endian_desc = 1; if (pdata->big_endian_mmio) ehci->big_endian_mmio = 1; if (pdata->has_tt) hcd->has_tt = 1; if (pdata->reset_on_resume) priv->reset_on_resume = true; #ifndef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO if (ehci->big_endian_mmio) { dev_err(&dev->dev, "Error: CONFIG_USB_EHCI_BIG_ENDIAN_MMIO not set\n"); err = -EINVAL; goto err_reset; } #endif #ifndef CONFIG_USB_EHCI_BIG_ENDIAN_DESC if (ehci->big_endian_desc) { dev_err(&dev->dev, "Error: CONFIG_USB_EHCI_BIG_ENDIAN_DESC not set\n"); err = -EINVAL; goto err_reset; } #endif if (pdata->power_on) { err = pdata->power_on(dev); if (err < 0) goto err_reset; } res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0); hcd->regs = devm_ioremap_resource(&dev->dev, res_mem); if (IS_ERR(hcd->regs)) { err = PTR_ERR(hcd->regs); goto err_power; } hcd->rsrc_start = res_mem->start; hcd->rsrc_len = resource_size(res_mem); err = usb_add_hcd(hcd, irq, IRQF_SHARED); if (err) goto err_power; device_wakeup_enable(hcd->self.controller); platform_set_drvdata(dev, hcd); return err; err_power: if (pdata->power_off) pdata->power_off(dev); err_reset: if (priv->rst) reset_control_assert(priv->rst); err_put_clks: while (--clk >= 0) clk_put(priv->clks[clk]); err_put_hcd: if (pdata == &ehci_platform_defaults) dev->dev.platform_data = NULL; usb_put_hcd(hcd); return err; }
static int ohci_platform_probe(struct platform_device *dev) { struct usb_hcd *hcd; struct resource *res_mem; struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev); struct ohci_platform_priv *priv; struct ohci_hcd *ohci; int err, irq, phy_num, clk = 0, rst = 0; if (usb_disabled()) return -ENODEV; /* * Use reasonable defaults so platforms don't have to provide these * with DT probing on ARM. */ if (!pdata) pdata = &ohci_platform_defaults; err = dma_coerce_mask_and_coherent(&dev->dev, DMA_BIT_MASK(32)); if (err) return err; irq = platform_get_irq(dev, 0); if (irq < 0) { dev_err(&dev->dev, "no irq provided"); return irq; } hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev, dev_name(&dev->dev)); if (!hcd) return -ENOMEM; platform_set_drvdata(dev, hcd); dev->dev.platform_data = pdata; priv = hcd_to_ohci_priv(hcd); ohci = hcd_to_ohci(hcd); if (pdata == &ohci_platform_defaults && dev->dev.of_node) { if (of_property_read_bool(dev->dev.of_node, "big-endian-regs")) ohci->flags |= OHCI_QUIRK_BE_MMIO; if (of_property_read_bool(dev->dev.of_node, "big-endian-desc")) ohci->flags |= OHCI_QUIRK_BE_DESC; if (of_property_read_bool(dev->dev.of_node, "big-endian")) ohci->flags |= OHCI_QUIRK_BE_MMIO | OHCI_QUIRK_BE_DESC; if (of_property_read_bool(dev->dev.of_node, "no-big-frame-no")) ohci->flags |= OHCI_QUIRK_FRAME_NO; of_property_read_u32(dev->dev.of_node, "num-ports", &ohci->num_ports); priv->num_phys = of_count_phandle_with_args(dev->dev.of_node, "phys", "#phy-cells"); if (priv->num_phys > 0) { priv->phys = devm_kcalloc(&dev->dev, priv->num_phys, sizeof(struct phy *), GFP_KERNEL); if (!priv->phys) return -ENOMEM; } else priv->num_phys = 0; for (phy_num = 0; phy_num < priv->num_phys; phy_num++) { priv->phys[phy_num] = devm_of_phy_get_by_index( &dev->dev, dev->dev.of_node, phy_num); if (IS_ERR(priv->phys[phy_num])) { err = PTR_ERR(priv->phys[phy_num]); goto err_put_hcd; } } for (clk = 0; clk < OHCI_MAX_CLKS; clk++) { priv->clks[clk] = of_clk_get(dev->dev.of_node, clk); if (IS_ERR(priv->clks[clk])) { err = PTR_ERR(priv->clks[clk]); if (err == -EPROBE_DEFER) goto err_put_clks; priv->clks[clk] = NULL; break; } } for (rst = 0; rst < OHCI_MAX_RESETS; rst++) { priv->resets[rst] = devm_reset_control_get_shared_by_index( &dev->dev, rst); if (IS_ERR(priv->resets[rst])) { err = PTR_ERR(priv->resets[rst]); if (err == -EPROBE_DEFER) goto err_reset; priv->resets[rst] = NULL; break; } err = reset_control_deassert(priv->resets[rst]); if (err) goto err_reset; } } if (pdata->big_endian_desc) ohci->flags |= OHCI_QUIRK_BE_DESC; if (pdata->big_endian_mmio) ohci->flags |= OHCI_QUIRK_BE_MMIO; if (pdata->no_big_frame_no) ohci->flags |= OHCI_QUIRK_FRAME_NO; if (pdata->num_ports) ohci->num_ports = pdata->num_ports; #ifndef CONFIG_USB_OHCI_BIG_ENDIAN_MMIO if (ohci->flags & OHCI_QUIRK_BE_MMIO) { dev_err(&dev->dev, "Error: CONFIG_USB_OHCI_BIG_ENDIAN_MMIO not set\n"); err = -EINVAL; goto err_reset; } #endif #ifndef CONFIG_USB_OHCI_BIG_ENDIAN_DESC if (ohci->flags & OHCI_QUIRK_BE_DESC) { dev_err(&dev->dev, "Error: CONFIG_USB_OHCI_BIG_ENDIAN_DESC not set\n"); err = -EINVAL; goto err_reset; } #endif if (pdata->power_on) { err = pdata->power_on(dev); if (err < 0) goto err_reset; } res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0); hcd->regs = devm_ioremap_resource(&dev->dev, res_mem); if (IS_ERR(hcd->regs)) { err = PTR_ERR(hcd->regs); goto err_power; } hcd->rsrc_start = res_mem->start; hcd->rsrc_len = resource_size(res_mem); err = usb_add_hcd(hcd, irq, IRQF_SHARED); if (err) goto err_power; device_wakeup_enable(hcd->self.controller); platform_set_drvdata(dev, hcd); return err; err_power: if (pdata->power_off) pdata->power_off(dev); err_reset: while (--rst >= 0) reset_control_assert(priv->resets[rst]); err_put_clks: while (--clk >= 0) clk_put(priv->clks[clk]); err_put_hcd: if (pdata == &ohci_platform_defaults) dev->dev.platform_data = NULL; usb_put_hcd(hcd); return err; }
static int xhci_mtk_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct device_node *node = dev->of_node; struct xhci_hcd_mtk *mtk; const struct hc_driver *driver; struct xhci_hcd *xhci; struct resource *res; struct usb_hcd *hcd; struct phy *phy; int phy_num; int ret = -ENODEV; int irq; if (usb_disabled()) return -ENODEV; driver = &xhci_mtk_hc_driver; mtk = devm_kzalloc(dev, sizeof(*mtk), GFP_KERNEL); if (!mtk) return -ENOMEM; mtk->dev = dev; mtk->vbus = devm_regulator_get(dev, "vbus"); if (IS_ERR(mtk->vbus)) { dev_err(dev, "fail to get vbus\n"); return PTR_ERR(mtk->vbus); } mtk->vusb33 = devm_regulator_get(dev, "vusb33"); if (IS_ERR(mtk->vusb33)) { dev_err(dev, "fail to get vusb33\n"); return PTR_ERR(mtk->vusb33); } mtk->sys_clk = devm_clk_get(dev, "sys_ck"); if (IS_ERR(mtk->sys_clk)) { dev_err(dev, "fail to get sys_ck\n"); return PTR_ERR(mtk->sys_clk); } /* * reference clock is usually a "fixed-clock", make it optional * for backward compatibility and ignore the error if it does * not exist. */ mtk->ref_clk = devm_clk_get(dev, "ref_ck"); if (IS_ERR(mtk->ref_clk)) { if (PTR_ERR(mtk->ref_clk) == -EPROBE_DEFER) return -EPROBE_DEFER; mtk->ref_clk = NULL; } mtk->lpm_support = of_property_read_bool(node, "usb3-lpm-capable"); ret = usb_wakeup_of_property_parse(mtk, node); if (ret) return ret; mtk->num_phys = of_count_phandle_with_args(node, "phys", "#phy-cells"); if (mtk->num_phys > 0) { mtk->phys = devm_kcalloc(dev, mtk->num_phys, sizeof(*mtk->phys), GFP_KERNEL); if (!mtk->phys) return -ENOMEM; } else { mtk->num_phys = 0; } pm_runtime_enable(dev); pm_runtime_get_sync(dev); device_enable_async_suspend(dev); ret = xhci_mtk_ldos_enable(mtk); if (ret) goto disable_pm; ret = xhci_mtk_clks_enable(mtk); if (ret) goto disable_ldos; irq = platform_get_irq(pdev, 0); if (irq < 0) { ret = irq; goto disable_clk; } /* Initialize dma_mask and coherent_dma_mask to 32-bits */ ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32)); if (ret) goto disable_clk; if (!dev->dma_mask) dev->dma_mask = &dev->coherent_dma_mask; else dma_set_mask(dev, DMA_BIT_MASK(32)); hcd = usb_create_hcd(driver, dev, dev_name(dev)); if (!hcd) { ret = -ENOMEM; goto disable_clk; } /* * USB 2.0 roothub is stored in the platform_device. * Swap it with mtk HCD. */ mtk->hcd = platform_get_drvdata(pdev); platform_set_drvdata(pdev, mtk); res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mac"); hcd->regs = devm_ioremap_resource(dev, res); if (IS_ERR(hcd->regs)) { ret = PTR_ERR(hcd->regs); goto put_usb2_hcd; } hcd->rsrc_start = res->start; hcd->rsrc_len = resource_size(res); res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ippc"); if (res) { /* ippc register is optional */ mtk->ippc_regs = devm_ioremap_resource(dev, res); if (IS_ERR(mtk->ippc_regs)) { ret = PTR_ERR(mtk->ippc_regs); goto put_usb2_hcd; } mtk->has_ippc = true; } else { mtk->has_ippc = false; } for (phy_num = 0; phy_num < mtk->num_phys; phy_num++) { phy = devm_of_phy_get_by_index(dev, node, phy_num); if (IS_ERR(phy)) { ret = PTR_ERR(phy); goto put_usb2_hcd; } mtk->phys[phy_num] = phy; } ret = xhci_mtk_phy_init(mtk); if (ret) goto put_usb2_hcd; ret = xhci_mtk_phy_power_on(mtk); if (ret) goto exit_phys; device_init_wakeup(dev, true); xhci = hcd_to_xhci(hcd); xhci->main_hcd = hcd; xhci->shared_hcd = usb_create_shared_hcd(driver, dev, dev_name(dev), hcd); if (!xhci->shared_hcd) { ret = -ENOMEM; goto power_off_phys; } ret = usb_add_hcd(hcd, irq, IRQF_SHARED); if (ret) goto put_usb3_hcd; if (HCC_MAX_PSA(xhci->hcc_params) >= 4) xhci->shared_hcd->can_do_streams = 1; ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED); if (ret) goto dealloc_usb2_hcd; return 0; dealloc_usb2_hcd: usb_remove_hcd(hcd); put_usb3_hcd: xhci_mtk_sch_exit(mtk); usb_put_hcd(xhci->shared_hcd); power_off_phys: xhci_mtk_phy_power_off(mtk); device_init_wakeup(dev, false); exit_phys: xhci_mtk_phy_exit(mtk); put_usb2_hcd: usb_put_hcd(hcd); disable_clk: xhci_mtk_clks_disable(mtk); disable_ldos: xhci_mtk_ldos_disable(mtk); disable_pm: pm_runtime_put_sync(dev); pm_runtime_disable(dev); return ret; }
static int get_ssusb_rscs(struct platform_device *pdev, struct ssusb_mtk *ssusb) { struct device_node *node = pdev->dev.of_node; struct otg_switch_mtk *otg_sx = &ssusb->otg_switch; struct device *dev = &pdev->dev; struct regulator *vbus; struct resource *res; int i; int ret; ssusb->vusb33 = devm_regulator_get(&pdev->dev, "vusb33"); if (IS_ERR(ssusb->vusb33)) { dev_err(dev, "failed to get vusb33\n"); return PTR_ERR(ssusb->vusb33); } ssusb->sys_clk = devm_clk_get(dev, "sys_ck"); if (IS_ERR(ssusb->sys_clk)) { dev_err(dev, "failed to get sys clock\n"); return PTR_ERR(ssusb->sys_clk); } ssusb->ref_clk = get_optional_clk(dev, "ref_ck"); if (IS_ERR(ssusb->ref_clk)) return PTR_ERR(ssusb->ref_clk); ssusb->mcu_clk = get_optional_clk(dev, "mcu_ck"); if (IS_ERR(ssusb->mcu_clk)) return PTR_ERR(ssusb->mcu_clk); ssusb->dma_clk = get_optional_clk(dev, "dma_ck"); if (IS_ERR(ssusb->dma_clk)) return PTR_ERR(ssusb->dma_clk); ssusb->num_phys = of_count_phandle_with_args(node, "phys", "#phy-cells"); if (ssusb->num_phys > 0) { ssusb->phys = devm_kcalloc(dev, ssusb->num_phys, sizeof(*ssusb->phys), GFP_KERNEL); if (!ssusb->phys) return -ENOMEM; } else { ssusb->num_phys = 0; } for (i = 0; i < ssusb->num_phys; i++) { ssusb->phys[i] = devm_of_phy_get_by_index(dev, node, i); if (IS_ERR(ssusb->phys[i])) { dev_err(dev, "failed to get phy-%d\n", i); return PTR_ERR(ssusb->phys[i]); } } res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ippc"); ssusb->ippc_base = devm_ioremap_resource(dev, res); if (IS_ERR(ssusb->ippc_base)) return PTR_ERR(ssusb->ippc_base); ssusb->dr_mode = usb_get_dr_mode(dev); if (ssusb->dr_mode == USB_DR_MODE_UNKNOWN) ssusb->dr_mode = USB_DR_MODE_OTG; if (ssusb->dr_mode == USB_DR_MODE_PERIPHERAL) return 0; /* if host role is supported */ ret = ssusb_wakeup_of_property_parse(ssusb, node); if (ret) { dev_err(dev, "failed to parse uwk property\n"); return ret; } /* optional property, ignore the error if it does not exist */ of_property_read_u32(node, "mediatek,u3p-dis-msk", &ssusb->u3p_dis_msk); vbus = devm_regulator_get(&pdev->dev, "vbus"); if (IS_ERR(vbus)) { dev_err(dev, "failed to get vbus\n"); return PTR_ERR(vbus); } otg_sx->vbus = vbus; if (ssusb->dr_mode == USB_DR_MODE_HOST) return 0; /* if dual-role mode is supported */ otg_sx->is_u3_drd = of_property_read_bool(node, "mediatek,usb3-drd"); otg_sx->manual_drd_enabled = of_property_read_bool(node, "enable-manual-drd"); if (of_property_read_bool(node, "extcon")) { otg_sx->edev = extcon_get_edev_by_phandle(ssusb->dev, 0); if (IS_ERR(otg_sx->edev)) { dev_err(ssusb->dev, "couldn't get extcon device\n"); return PTR_ERR(otg_sx->edev); } } dev_info(dev, "dr_mode: %d, is_u3_dr: %d, u3p_dis_msk: %x, drd: %s\n", ssusb->dr_mode, otg_sx->is_u3_drd, ssusb->u3p_dis_msk, otg_sx->manual_drd_enabled ? "manual" : "auto"); return 0; }