int dwc3_host_init(struct dwc3 *dwc) { struct platform_device *xhci; struct usb_xhci_pdata pdata; int ret; xhci = platform_device_alloc("xhci-hcd", PLATFORM_DEVID_AUTO); if (!xhci) { dev_err(dwc->dev, "couldn't allocate xHCI device\n"); return -ENOMEM; } dma_set_coherent_mask(&xhci->dev, dwc->dev->coherent_dma_mask); xhci->dev.parent = dwc->dev; xhci->dev.dma_mask = dwc->dev->dma_mask; xhci->dev.dma_parms = dwc->dev->dma_parms; dwc->xhci = xhci; ret = platform_device_add_resources(xhci, dwc->xhci_resources, DWC3_XHCI_RESOURCES_NUM); if (ret) { dev_err(dwc->dev, "couldn't add resources to xHCI device\n"); goto err1; } memset(&pdata, 0, sizeof(pdata)); #ifdef CONFIG_DWC3_HOST_USB3_LPM_ENABLE pdata.usb3_lpm_capable = 1; #endif ret = platform_device_add_data(xhci, &pdata, sizeof(pdata)); if (ret) { dev_err(dwc->dev, "couldn't add platform data to xHCI device\n"); goto err1; } phy_create_lookup(dwc->usb2_generic_phy, "usb2-phy", dev_name(&xhci->dev)); phy_create_lookup(dwc->usb3_generic_phy, "usb3-phy", dev_name(&xhci->dev)); ret = platform_device_add(xhci); if (ret) { dev_err(dwc->dev, "failed to register xHCI device\n"); goto err2; } return 0; err2: phy_remove_lookup(dwc->usb2_generic_phy, "usb2-phy", dev_name(&xhci->dev)); phy_remove_lookup(dwc->usb3_generic_phy, "usb3-phy", dev_name(&xhci->dev)); err1: platform_device_put(xhci); return ret; }
static int da8xx_usb_phy_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct device_node *node = dev->of_node; struct da8xx_usb_phy *d_phy; d_phy = devm_kzalloc(dev, sizeof(*d_phy), GFP_KERNEL); if (!d_phy) return -ENOMEM; if (node) d_phy->regmap = syscon_regmap_lookup_by_compatible( "ti,da830-cfgchip"); else d_phy->regmap = syscon_regmap_lookup_by_pdevname("syscon.0"); if (IS_ERR(d_phy->regmap)) { dev_err(dev, "Failed to get syscon\n"); return PTR_ERR(d_phy->regmap); } d_phy->usb11_clk = devm_clk_get(dev, "usb11_phy"); if (IS_ERR(d_phy->usb11_clk)) { dev_err(dev, "Failed to get usb11_phy clock\n"); return PTR_ERR(d_phy->usb11_clk); } d_phy->usb20_clk = devm_clk_get(dev, "usb20_phy"); if (IS_ERR(d_phy->usb20_clk)) { dev_err(dev, "Failed to get usb20_phy clock\n"); return PTR_ERR(d_phy->usb20_clk); } d_phy->usb11_phy = devm_phy_create(dev, node, &da8xx_usb11_phy_ops); if (IS_ERR(d_phy->usb11_phy)) { dev_err(dev, "Failed to create usb11 phy\n"); return PTR_ERR(d_phy->usb11_phy); } d_phy->usb20_phy = devm_phy_create(dev, node, &da8xx_usb20_phy_ops); if (IS_ERR(d_phy->usb20_phy)) { dev_err(dev, "Failed to create usb20 phy\n"); return PTR_ERR(d_phy->usb20_phy); } platform_set_drvdata(pdev, d_phy); phy_set_drvdata(d_phy->usb11_phy, d_phy); phy_set_drvdata(d_phy->usb20_phy, d_phy); if (node) { d_phy->phy_provider = devm_of_phy_provider_register(dev, da8xx_usb_phy_of_xlate); if (IS_ERR(d_phy->phy_provider)) { dev_err(dev, "Failed to create phy provider\n"); return PTR_ERR(d_phy->phy_provider); } } else { int ret; ret = phy_create_lookup(d_phy->usb11_phy, "usb-phy", "ohci.0"); if (ret) dev_warn(dev, "Failed to create usb11 phy lookup\n"); ret = phy_create_lookup(d_phy->usb20_phy, "usb-phy", "musb-da8xx"); if (ret) dev_warn(dev, "Failed to create usb20 phy lookup\n"); } return 0; }
static int twl4030_usb_probe(struct platform_device *pdev) { struct twl4030_usb_data *pdata = dev_get_platdata(&pdev->dev); struct twl4030_usb *twl; struct phy *phy; int status, err; struct usb_otg *otg; struct device_node *np = pdev->dev.of_node; struct phy_provider *phy_provider; twl = devm_kzalloc(&pdev->dev, sizeof(*twl), GFP_KERNEL); if (!twl) return -ENOMEM; if (np) of_property_read_u32(np, "usb_mode", (enum twl4030_usb_mode *)&twl->usb_mode); else if (pdata) { twl->usb_mode = pdata->usb_mode; } else { dev_err(&pdev->dev, "twl4030 initialized without pdata\n"); return -EINVAL; } otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL); if (!otg) return -ENOMEM; twl->dev = &pdev->dev; twl->irq = platform_get_irq(pdev, 0); twl->vbus_supplied = false; twl->linkstat = MUSB_UNKNOWN; twl->phy.dev = twl->dev; twl->phy.label = "twl4030"; twl->phy.otg = otg; twl->phy.type = USB_PHY_TYPE_USB2; otg->usb_phy = &twl->phy; otg->set_host = twl4030_set_host; otg->set_peripheral = twl4030_set_peripheral; phy = devm_phy_create(twl->dev, NULL, &ops); if (IS_ERR(phy)) { dev_dbg(&pdev->dev, "Failed to create PHY\n"); return PTR_ERR(phy); } phy_set_drvdata(phy, twl); phy_provider = devm_of_phy_provider_register(twl->dev, of_phy_simple_xlate); if (IS_ERR(phy_provider)) return PTR_ERR(phy_provider); /* init mutex for workqueue */ mutex_init(&twl->lock); INIT_DELAYED_WORK(&twl->id_workaround_work, twl4030_id_workaround_work); err = twl4030_usb_ldo_init(twl); if (err) { dev_err(&pdev->dev, "ldo init failed\n"); return err; } usb_add_phy_dev(&twl->phy); platform_set_drvdata(pdev, twl); if (device_create_file(&pdev->dev, &dev_attr_vbus)) dev_warn(&pdev->dev, "could not create sysfs file\n"); ATOMIC_INIT_NOTIFIER_HEAD(&twl->phy.notifier); pm_runtime_use_autosuspend(&pdev->dev); pm_runtime_set_autosuspend_delay(&pdev->dev, 2000); pm_runtime_enable(&pdev->dev); pm_runtime_get_sync(&pdev->dev); /* Our job is to use irqs and status from the power module * to keep the transceiver disabled when nothing's connected. * * FIXME we actually shouldn't start enabling it until the * USB controller drivers have said they're ready, by calling * set_host() and/or set_peripheral() ... OTG_capable boards * need both handles, otherwise just one suffices. */ status = devm_request_threaded_irq(twl->dev, twl->irq, NULL, twl4030_usb_irq, IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | IRQF_ONESHOT, "twl4030_usb", twl); if (status < 0) { dev_dbg(&pdev->dev, "can't get IRQ %d, err %d\n", twl->irq, status); return status; } if (pdata) err = phy_create_lookup(phy, "usb", "musb-hdrc.0"); if (err) return err; pm_runtime_mark_last_busy(&pdev->dev); pm_runtime_put_autosuspend(twl->dev); dev_info(&pdev->dev, "Initialized TWL4030 USB module\n"); return 0; }
int dwc3_host_init(struct dwc3 *dwc) { struct property_entry props[2]; struct platform_device *xhci; int ret, irq; struct resource *res; struct platform_device *dwc3_pdev = to_platform_device(dwc->dev); irq = dwc3_host_get_irq(dwc); if (irq < 0) return irq; res = platform_get_resource_byname(dwc3_pdev, IORESOURCE_IRQ, "host"); if (!res) res = platform_get_resource_byname(dwc3_pdev, IORESOURCE_IRQ, "dwc_usb3"); if (!res) res = platform_get_resource(dwc3_pdev, IORESOURCE_IRQ, 0); if (!res) return -ENOMEM; dwc->xhci_resources[1].start = irq; dwc->xhci_resources[1].end = irq; dwc->xhci_resources[1].flags = res->flags; dwc->xhci_resources[1].name = res->name; xhci = platform_device_alloc("xhci-hcd", PLATFORM_DEVID_AUTO); if (!xhci) { dev_err(dwc->dev, "couldn't allocate xHCI device\n"); return -ENOMEM; } xhci->dev.parent = dwc->dev; dwc->xhci = xhci; ret = platform_device_add_resources(xhci, dwc->xhci_resources, DWC3_XHCI_RESOURCES_NUM); if (ret) { dev_err(dwc->dev, "couldn't add resources to xHCI device\n"); goto err1; } memset(props, 0, sizeof(struct property_entry) * ARRAY_SIZE(props)); if (dwc->usb3_lpm_capable) { props[0].name = "usb3-lpm-capable"; ret = platform_device_add_properties(xhci, props); if (ret) { dev_err(dwc->dev, "failed to add properties to xHCI\n"); goto err1; } } phy_create_lookup(dwc->usb2_generic_phy, "usb2-phy", dev_name(dwc->dev)); phy_create_lookup(dwc->usb3_generic_phy, "usb3-phy", dev_name(dwc->dev)); ret = platform_device_add(xhci); if (ret) { dev_err(dwc->dev, "failed to register xHCI device\n"); goto err2; } return 0; err2: phy_remove_lookup(dwc->usb2_generic_phy, "usb2-phy", dev_name(dwc->dev)); phy_remove_lookup(dwc->usb3_generic_phy, "usb3-phy", dev_name(dwc->dev)); err1: platform_device_put(xhci); return ret; }