UPSTREAM: usb: dwc3: core: cleanup IRQ resources
authorRoger Quadros <rogerq@ti.com>
Fri, 10 Jun 2016 11:48:38 +0000 (14:48 +0300)
committerHuang, Tao <huangtao@rock-chips.com>
Tue, 16 Aug 2016 12:48:19 +0000 (20:48 +0800)
Implementations might use different IRQs for
host, gadget so use named interrupt resources
to allow device tree to specify the interrupts.

Following are the interrupt names

Peripheral Interrupt - peripheral
HOST Interrupt - host

Maintain backward compatibility for a single named
interrupt ("dwc3_usb3") for all interrupts as well as
unnamed interrupt at index 0 for all interrupts.

As platform_get_irq() variants are used, tackle
the -EPROBE_DEFER case as well.

Change-Id: Idb47d85ceee3353a219e4a9793942c7e92a6a6eb
Signed-off-by: Roger Quadros <rogerq@ti.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
(cherry picked from commit 9522def40065194aa75b0a7b7e1ff5b8e2014724)

Conflicts:
drivers/usb/dwc3/core.c

drivers/usb/dwc3/core.c
drivers/usb/dwc3/gadget.c
drivers/usb/dwc3/host.c

index bbbe90ce58f0394612dec608855daf8810795509..ae93fa0861fde31ea05f65fbc459cef72a958f36 100644 (file)
@@ -766,7 +766,8 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)
                dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
                ret = dwc3_gadget_init(dwc);
                if (ret) {
-                       dev_err(dev, "failed to initialize gadget\n");
+                       if (ret != -EPROBE_DEFER)
+                               dev_err(dev, "failed to initialize gadget\n");
                        return ret;
                }
                break;
@@ -774,7 +775,8 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)
                dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST);
                ret = dwc3_host_init(dwc);
                if (ret) {
-                       dev_err(dev, "failed to initialize host\n");
+                       if (ret != -EPROBE_DEFER)
+                               dev_err(dev, "failed to initialize host\n");
                        return ret;
                }
                break;
@@ -782,13 +784,15 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)
                dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
                ret = dwc3_host_init(dwc);
                if (ret) {
-                       dev_err(dev, "failed to initialize host\n");
+                       if (ret != -EPROBE_DEFER)
+                               dev_err(dev, "failed to initialize host\n");
                        return ret;
                }
 
                ret = dwc3_gadget_init(dwc);
                if (ret) {
-                       dev_err(dev, "failed to initialize gadget\n");
+                       if (ret != -EPROBE_DEFER)
+                               dev_err(dev, "failed to initialize gadget\n");
                        return ret;
                }
                break;
@@ -858,16 +862,6 @@ static int dwc3_probe(struct platform_device *pdev)
                        return ret;
        }
 
-       res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
-       if (!res) {
-               dev_err(dev, "missing IRQ\n");
-               return -ENODEV;
-       }
-       dwc->xhci_resources[1].start = res->start;
-       dwc->xhci_resources[1].end = res->end;
-       dwc->xhci_resources[1].flags = res->flags;
-       dwc->xhci_resources[1].name = res->name;
-
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        if (!res) {
                dev_err(dev, "missing memory resource\n");
index 5f29061faa97a08f31a82e493bd548ff432b3288..7bd4393dfe8ac702d044d829d6ced127268b3c9a 100644 (file)
@@ -1769,7 +1769,7 @@ static int dwc3_gadget_start(struct usb_gadget *g,
        int                     ret = 0;
        int                     irq;
 
-       irq = platform_get_irq(to_platform_device(dwc->dev), 0);
+       irq = dwc->irq_gadget;
        ret = request_threaded_irq(irq, dwc3_interrupt, dwc3_thread_interrupt,
                        IRQF_SHARED, "dwc3", dwc->ev_buf);
        if (ret) {
@@ -1777,7 +1777,6 @@ static int dwc3_gadget_start(struct usb_gadget *g,
                                irq, ret);
                goto err0;
        }
-       dwc->irq_gadget = irq;
 
        spin_lock_irqsave(&dwc->lock, flags);
        if (dwc->gadget_driver) {
@@ -2888,7 +2887,33 @@ static irqreturn_t dwc3_interrupt(int irq, void *_evt)
  */
 int dwc3_gadget_init(struct dwc3 *dwc)
 {
-       int                                     ret;
+       int ret, irq;
+       struct platform_device *dwc3_pdev = to_platform_device(dwc->dev);
+
+       irq = platform_get_irq_byname(dwc3_pdev, "peripheral");
+       if (irq == -EPROBE_DEFER)
+               return irq;
+
+       if (irq <= 0) {
+               irq = platform_get_irq_byname(dwc3_pdev, "dwc_usb3");
+               if (irq == -EPROBE_DEFER)
+                       return irq;
+
+               if (irq <= 0) {
+                       irq = platform_get_irq(dwc3_pdev, 0);
+                       if (irq <= 0) {
+                               if (irq != -EPROBE_DEFER) {
+                                       dev_err(dwc->dev,
+                                               "missing peripheral IRQ\n");
+                               }
+                               if (!irq)
+                                       irq = -EINVAL;
+                               return irq;
+                       }
+               }
+       }
+
+       dwc->irq_gadget = irq;
 
        dwc->ctrl_req = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ctrl_req),
                        &dwc->ctrl_req_addr, GFP_KERNEL);
index 661fbae01ae2d1556245528311afdb079de63657..2903c9102cbd8fa9fa1b8d05f6e93d888c53c359 100644 (file)
@@ -24,7 +24,48 @@ int dwc3_host_init(struct dwc3 *dwc)
 {
        struct platform_device  *xhci;
        struct usb_xhci_pdata   pdata;
-       int                     ret;
+       int                     ret, irq;
+       struct resource         *res;
+       struct platform_device  *dwc3_pdev = to_platform_device(dwc->dev);
+
+       irq = platform_get_irq_byname(dwc3_pdev, "host");
+       if (irq == -EPROBE_DEFER)
+               return irq;
+
+       if (irq <= 0) {
+               irq = platform_get_irq_byname(dwc3_pdev, "dwc_usb3");
+               if (irq == -EPROBE_DEFER)
+                       return irq;
+
+               if (irq <= 0) {
+                       irq = platform_get_irq(dwc3_pdev, 0);
+                       if (irq <= 0) {
+                               if (irq != -EPROBE_DEFER) {
+                                       dev_err(dwc->dev,
+                                               "missing host IRQ\n");
+                               }
+                               if (!irq)
+                                       irq = -EINVAL;
+                               return irq;
+                       } else {
+                               res = platform_get_resource(dwc3_pdev,
+                                                           IORESOURCE_IRQ, 0);
+                       }
+               } else {
+                       res = platform_get_resource_byname(dwc3_pdev,
+                                                          IORESOURCE_IRQ,
+                                                          "dwc_usb3");
+               }
+
+       } else {
+               res = platform_get_resource_byname(dwc3_pdev, IORESOURCE_IRQ,
+                                                  "host");
+       }
+
+       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) {