0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/irq.h>
0011 #include <linux/of.h>
0012 #include <linux/platform_device.h>
0013
0014 #include "../host/xhci-plat.h"
0015 #include "core.h"
0016
0017 static const struct xhci_plat_priv dwc3_xhci_plat_priv = {
0018 .quirks = XHCI_SKIP_PHY_INIT,
0019 };
0020
0021 static void dwc3_host_fill_xhci_irq_res(struct dwc3 *dwc,
0022 int irq, char *name)
0023 {
0024 struct platform_device *pdev = to_platform_device(dwc->dev);
0025 struct device_node *np = dev_of_node(&pdev->dev);
0026
0027 dwc->xhci_resources[1].start = irq;
0028 dwc->xhci_resources[1].end = irq;
0029 dwc->xhci_resources[1].flags = IORESOURCE_IRQ | irq_get_trigger_type(irq);
0030 if (!name && np)
0031 dwc->xhci_resources[1].name = of_node_full_name(pdev->dev.of_node);
0032 else
0033 dwc->xhci_resources[1].name = name;
0034 }
0035
0036 static int dwc3_host_get_irq(struct dwc3 *dwc)
0037 {
0038 struct platform_device *dwc3_pdev = to_platform_device(dwc->dev);
0039 int irq;
0040
0041 irq = platform_get_irq_byname_optional(dwc3_pdev, "host");
0042 if (irq > 0) {
0043 dwc3_host_fill_xhci_irq_res(dwc, irq, "host");
0044 goto out;
0045 }
0046
0047 if (irq == -EPROBE_DEFER)
0048 goto out;
0049
0050 irq = platform_get_irq_byname_optional(dwc3_pdev, "dwc_usb3");
0051 if (irq > 0) {
0052 dwc3_host_fill_xhci_irq_res(dwc, irq, "dwc_usb3");
0053 goto out;
0054 }
0055
0056 if (irq == -EPROBE_DEFER)
0057 goto out;
0058
0059 irq = platform_get_irq(dwc3_pdev, 0);
0060 if (irq > 0) {
0061 dwc3_host_fill_xhci_irq_res(dwc, irq, NULL);
0062 goto out;
0063 }
0064
0065 if (!irq)
0066 irq = -EINVAL;
0067
0068 out:
0069 return irq;
0070 }
0071
0072 int dwc3_host_init(struct dwc3 *dwc)
0073 {
0074 struct property_entry props[4];
0075 struct platform_device *xhci;
0076 int ret, irq;
0077 int prop_idx = 0;
0078
0079 irq = dwc3_host_get_irq(dwc);
0080 if (irq < 0)
0081 return irq;
0082
0083 xhci = platform_device_alloc("xhci-hcd", PLATFORM_DEVID_AUTO);
0084 if (!xhci) {
0085 dev_err(dwc->dev, "couldn't allocate xHCI device\n");
0086 return -ENOMEM;
0087 }
0088
0089 xhci->dev.parent = dwc->dev;
0090
0091 dwc->xhci = xhci;
0092
0093 ret = platform_device_add_resources(xhci, dwc->xhci_resources,
0094 DWC3_XHCI_RESOURCES_NUM);
0095 if (ret) {
0096 dev_err(dwc->dev, "couldn't add resources to xHCI device\n");
0097 goto err;
0098 }
0099
0100 ret = platform_device_add_data(xhci, &dwc3_xhci_plat_priv,
0101 sizeof(dwc3_xhci_plat_priv));
0102 if (ret)
0103 goto err;
0104
0105 memset(props, 0, sizeof(struct property_entry) * ARRAY_SIZE(props));
0106
0107 if (dwc->usb3_lpm_capable)
0108 props[prop_idx++] = PROPERTY_ENTRY_BOOL("usb3-lpm-capable");
0109
0110 if (dwc->usb2_lpm_disable)
0111 props[prop_idx++] = PROPERTY_ENTRY_BOOL("usb2-lpm-disable");
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122 if (DWC3_VER_IS_WITHIN(DWC3, ANY, 300A))
0123 props[prop_idx++] = PROPERTY_ENTRY_BOOL("quirk-broken-port-ped");
0124
0125 if (prop_idx) {
0126 ret = device_create_managed_software_node(&xhci->dev, props, NULL);
0127 if (ret) {
0128 dev_err(dwc->dev, "failed to add properties to xHCI\n");
0129 goto err;
0130 }
0131 }
0132
0133 ret = platform_device_add(xhci);
0134 if (ret) {
0135 dev_err(dwc->dev, "failed to register xHCI device\n");
0136 goto err;
0137 }
0138
0139 return 0;
0140 err:
0141 platform_device_put(xhci);
0142 return ret;
0143 }
0144
0145 void dwc3_host_exit(struct dwc3 *dwc)
0146 {
0147 platform_device_unregister(dwc->xhci);
0148 dwc->xhci = NULL;
0149 }