diff mbox

[v10,5/5] usb: dwc3: core: cleanup IRQ resources

Message ID 575A8EB0.1050706@ti.com
State Superseded
Headers show

Commit Message

Roger Quadros June 10, 2016, 9:56 a.m. UTC
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.

Signed-off-by: Roger Quadros <rogerq@ti.com>

---
v10:
- don't mention otg irq since we are not using it yet
- use platform_get_irq() and friends and check -EPROBE_DEFER case.

 drivers/usb/dwc3/core.c   | 22 ++++++++--------------
 drivers/usb/dwc3/gadget.c | 29 ++++++++++++++++++++++++++---
 drivers/usb/dwc3/host.c   | 41 ++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 74 insertions(+), 18 deletions(-)

-- 
2.7.4

Comments

Roger Quadros June 10, 2016, 11:35 a.m. UTC | #1
On 10/06/16 13:39, Sergei Shtylyov wrote:
> Hello.

> 

> On 6/10/2016 12:56 PM, Roger Quadros wrote:

> 

>> 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

> 

>    platform_get_irq().


OK.
> 

>> the -EPROBE_DEFER case as well.

>>

>> Signed-off-by: Roger Quadros <rogerq@ti.com>

>> ---

>> v10:

>> - don't mention otg irq since we are not using it yet

>> - use platform_get_irq() and friends and check -EPROBE_DEFER case.

>>

>>  drivers/usb/dwc3/core.c   | 22 ++++++++--------------

>>  drivers/usb/dwc3/gadget.c | 29 ++++++++++++++++++++++++++---

>>  drivers/usb/dwc3/host.c   | 41 ++++++++++++++++++++++++++++++++++++++++-

>>  3 files changed, 74 insertions(+), 18 deletions(-)

>>

>> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c

>> index 8fceeb1..131e7eb 100644

>> --- a/drivers/usb/dwc3/core.c

>> +++ b/drivers/usb/dwc3/core.c

> [...]

>> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c

>> index 0f6fb8e..774a0d8 100644

>> --- a/drivers/usb/dwc3/gadget.c

>> +++ b/drivers/usb/dwc3/gadget.c

> [...]

>> @@ -2866,7 +2865,31 @@ 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");

>> +                }

>> +                return irq;

> 

>    Iff irq == 0, you'll return success despite IRQ was "invalid". Was that intended?


good catch. It wasn't intended. I guess i'll return -EINVAL then?

> 

>> +            }

>> +        }

>> +    }

>> +

>> +    dwc->irq_gadget = irq;

>>

>>      dwc->ctrl_req = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ctrl_req),

>>              &dwc->ctrl_req_addr, GFP_KERNEL);

>> diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c

>> index c679f63..eb5e8f9 100644

>> --- a/drivers/usb/dwc3/host.c

>> +++ b/drivers/usb/dwc3/host.c

>> @@ -24,7 +24,46 @@ 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");

>> +                }

>> +                return irq;

> 

>    Iff irq == 0, you'll return success despite IRQ was "invalid". Was that intended?

> 

>> +            } 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) {

> 


--
cheers,
-roger
Roger Quadros June 10, 2016, 11:46 a.m. UTC | #2
On 10/06/16 14:44, Sergei Shtylyov wrote:
> On 6/10/2016 2:35 PM, Roger Quadros wrote:

>> On 10/06/16 13:39, Sergei Shtylyov wrote:

>>> Hello.

>>>

>>> On 6/10/2016 12:56 PM, Roger Quadros wrote:

>>>

>>>> 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

>>>

>>>    platform_get_irq().

>>

>> OK.

>>>

>>>> the -EPROBE_DEFER case as well.

>>>>

>>>> Signed-off-by: Roger Quadros <rogerq@ti.com>

>>>> ---

>>>> v10:

>>>> - don't mention otg irq since we are not using it yet

>>>> - use platform_get_irq() and friends and check -EPROBE_DEFER case.

>>>>

>>>>  drivers/usb/dwc3/core.c   | 22 ++++++++--------------

>>>>  drivers/usb/dwc3/gadget.c | 29 ++++++++++++++++++++++++++---

>>>>  drivers/usb/dwc3/host.c   | 41 ++++++++++++++++++++++++++++++++++++++++-

>>>>  3 files changed, 74 insertions(+), 18 deletions(-)

>>>>

>>>> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c

>>>> index 8fceeb1..131e7eb 100644

>>>> --- a/drivers/usb/dwc3/core.c

>>>> +++ b/drivers/usb/dwc3/core.c

>>> [...]

>>>> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c

>>>> index 0f6fb8e..774a0d8 100644

>>>> --- a/drivers/usb/dwc3/gadget.c

>>>> +++ b/drivers/usb/dwc3/gadget.c

>>> [...]

>>>> @@ -2866,7 +2865,31 @@ 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");

>>>> +                }

>>>> +                return irq;

>>>

>>>    Iff irq == 0, you'll return success despite IRQ was "invalid". Was that intended?

>>

>> good catch. It wasn't intended. I guess i'll return -EINVAL then?

>>

>>>

>>>> +            }

>>>> +        }

>>>> +    }

>>>> +

>>>> +    dwc->irq_gadget = irq;

>>>>

>>>>      dwc->ctrl_req = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ctrl_req),

>>>>              &dwc->ctrl_req_addr, GFP_KERNEL);

>>>> diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c

>>>> index c679f63..eb5e8f9 100644

>>>> --- a/drivers/usb/dwc3/host.c

>>>> +++ b/drivers/usb/dwc3/host.c

>>>> @@ -24,7 +24,46 @@ 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");

>>>> +                }

>>>> +                return irq;

>>>

>>>    Iff irq == 0, you'll return success despite IRQ was "invalid". Was that intended?

> 

>    I'd just consider 0 a valid IRQ, that's simpler. FYI, I've submitted to Greg KH a patch fixing platform_get_irq[_byname]() to not return 0 on failure. No reaction so far...


Maybe till your patch is in we can't really differentiate if it is error or not
so it is safer to consider it as error IMO.

cheers,
-roger
diff mbox

Patch

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 8fceeb1..131e7eb 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -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;
@@ -843,16 +847,6 @@  static int dwc3_probe(struct platform_device *pdev)
 	dwc->mem = mem;
 	dwc->dev = dev;
 
-	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");
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 0f6fb8e..774a0d8 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1738,7 +1738,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) {
@@ -1746,7 +1746,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) {
@@ -2866,7 +2865,31 @@  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");
+				}
+				return irq;
+			}
+		}
+	}
+
+	dwc->irq_gadget = irq;
 
 	dwc->ctrl_req = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ctrl_req),
 			&dwc->ctrl_req_addr, GFP_KERNEL);
diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
index c679f63..eb5e8f9 100644
--- a/drivers/usb/dwc3/host.c
+++ b/drivers/usb/dwc3/host.c
@@ -24,7 +24,46 @@  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");
+				}
+				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) {