linux-omap.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/5] omap_udc bug fixes
@ 2018-11-24 22:17 Aaro Koskinen
  2018-11-24 22:17 ` [PATCH v2 1/5] USB: omap_udc: use devm_request_irq() Aaro Koskinen
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Aaro Koskinen @ 2018-11-24 22:17 UTC (permalink / raw)
  To: Felipe Balbi, linux-usb
  Cc: linux-kernel, linux-omap, Tony Lindgren, Aaro Koskinen

Hello,

Some fixes for omap_udc making the driver usable again on Palm TE & 770.

	v2: Patch #2 rewritten, now usb_add_gadget_udc_release() should be
	    properly used.
	    Patch #5 added.

	v1: https://marc.info/?l=linux-usb&m=154258778216930&w=2
	    https://marc.info/?l=linux-usb&m=154258778316932&w=2
	    https://marc.info/?l=linux-usb&m=154258778316931&w=2
	    https://marc.info/?l=linux-usb&m=154258778216929&w=2

Aaro Koskinen (5):
  USB: omap_udc: use devm_request_irq()
  USB: omap_udc: fix crashes on probe error and module removal
  USB: omap_udc: fix omap_udc_start() on 15xx machines
  USB: omap_udc: fix USB gadget functionality on Palm Tungsten E
  USB: omap_udc: fix rejection of out transfers when DMA is used

 drivers/usb/gadget/udc/omap_udc.c | 88 +++++++++++--------------------
 1 file changed, 31 insertions(+), 57 deletions(-)

-- 
2.17.0

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/5] USB: omap_udc: use devm_request_irq()
  2018-11-24 22:17 [PATCH v2 0/5] omap_udc bug fixes Aaro Koskinen
@ 2018-11-24 22:17 ` Aaro Koskinen
  2018-11-24 22:17 ` [PATCH v2 2/5] USB: omap_udc: fix crashes on probe error and module removal Aaro Koskinen
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Aaro Koskinen @ 2018-11-24 22:17 UTC (permalink / raw)
  To: Felipe Balbi, linux-usb
  Cc: linux-kernel, linux-omap, Tony Lindgren, Aaro Koskinen

The current code fails to release the third irq on the error path
(observed by reading the code), and we get also multiple WARNs with
failing gadget drivers due to duplicate IRQ releases. Fix by using
devm_request_irq().

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
---
 drivers/usb/gadget/udc/omap_udc.c | 37 +++++++++----------------------
 1 file changed, 10 insertions(+), 27 deletions(-)

diff --git a/drivers/usb/gadget/udc/omap_udc.c b/drivers/usb/gadget/udc/omap_udc.c
index 3a16431da321..1c77218c82af 100644
--- a/drivers/usb/gadget/udc/omap_udc.c
+++ b/drivers/usb/gadget/udc/omap_udc.c
@@ -2867,8 +2867,8 @@ static int omap_udc_probe(struct platform_device *pdev)
 		udc->clr_halt = UDC_RESET_EP;
 
 	/* USB general purpose IRQ:  ep0, state changes, dma, etc */
-	status = request_irq(pdev->resource[1].start, omap_udc_irq,
-			0, driver_name, udc);
+	status = devm_request_irq(&pdev->dev, pdev->resource[1].start,
+				  omap_udc_irq, 0, driver_name, udc);
 	if (status != 0) {
 		ERR("can't get irq %d, err %d\n",
 			(int) pdev->resource[1].start, status);
@@ -2876,20 +2876,20 @@ static int omap_udc_probe(struct platform_device *pdev)
 	}
 
 	/* USB "non-iso" IRQ (PIO for all but ep0) */
-	status = request_irq(pdev->resource[2].start, omap_udc_pio_irq,
-			0, "omap_udc pio", udc);
+	status = devm_request_irq(&pdev->dev, pdev->resource[2].start,
+				  omap_udc_pio_irq, 0, "omap_udc pio", udc);
 	if (status != 0) {
 		ERR("can't get irq %d, err %d\n",
 			(int) pdev->resource[2].start, status);
-		goto cleanup2;
+		goto cleanup1;
 	}
 #ifdef	USE_ISO
-	status = request_irq(pdev->resource[3].start, omap_udc_iso_irq,
-			0, "omap_udc iso", udc);
+	status = devm_request_irq(&pdev->dev, pdev->resource[3].start,
+				  omap_udc_iso_irq, 0, "omap_udc iso", udc);
 	if (status != 0) {
 		ERR("can't get irq %d, err %d\n",
 			(int) pdev->resource[3].start, status);
-		goto cleanup3;
+		goto cleanup1;
 	}
 #endif
 	if (cpu_is_omap16xx() || cpu_is_omap7xx()) {
@@ -2902,22 +2902,11 @@ static int omap_udc_probe(struct platform_device *pdev)
 	create_proc_file();
 	status = usb_add_gadget_udc_release(&pdev->dev, &udc->gadget,
 			omap_udc_release);
-	if (status)
-		goto cleanup4;
-
-	return 0;
+	if (!status)
+		return 0;
 
-cleanup4:
 	remove_proc_file();
 
-#ifdef	USE_ISO
-cleanup3:
-	free_irq(pdev->resource[2].start, udc);
-#endif
-
-cleanup2:
-	free_irq(pdev->resource[1].start, udc);
-
 cleanup1:
 	kfree(udc);
 	udc = NULL;
@@ -2961,12 +2950,6 @@ static int omap_udc_remove(struct platform_device *pdev)
 
 	remove_proc_file();
 
-#ifdef	USE_ISO
-	free_irq(pdev->resource[3].start, udc);
-#endif
-	free_irq(pdev->resource[2].start, udc);
-	free_irq(pdev->resource[1].start, udc);
-
 	if (udc->dc_clk) {
 		if (udc->clk_requested)
 			omap_udc_enable_clock(0);
-- 
2.17.0

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 2/5] USB: omap_udc: fix crashes on probe error and module removal
  2018-11-24 22:17 [PATCH v2 0/5] omap_udc bug fixes Aaro Koskinen
  2018-11-24 22:17 ` [PATCH v2 1/5] USB: omap_udc: use devm_request_irq() Aaro Koskinen
@ 2018-11-24 22:17 ` Aaro Koskinen
  2018-11-24 22:17 ` [PATCH v2 3/5] USB: omap_udc: fix omap_udc_start() on 15xx machines Aaro Koskinen
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Aaro Koskinen @ 2018-11-24 22:17 UTC (permalink / raw)
  To: Felipe Balbi, linux-usb
  Cc: linux-kernel, linux-omap, Tony Lindgren, Aaro Koskinen

We currently crash if usb_add_gadget_udc_release() fails, since the
udc->done is not initialized until in the remove function.
Furthermore, on module removal the udc data is accessed although
the release function is already triggered by usb_del_gadget_udc()
early in the function.

Fix by rewriting the release and remove functions, basically moving
all the cleanup into the release function, and doing the completion
only in the module removal case.

The patch fixes omap_udc module probe with a failing gadged, and also
allows the removal of omap_udc. Tested by running "modprobe omap_udc;
modprobe -r omap_udc" in a loop.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
---
 drivers/usb/gadget/udc/omap_udc.c | 50 ++++++++++++-------------------
 1 file changed, 19 insertions(+), 31 deletions(-)

diff --git a/drivers/usb/gadget/udc/omap_udc.c b/drivers/usb/gadget/udc/omap_udc.c
index 1c77218c82af..240ccba44592 100644
--- a/drivers/usb/gadget/udc/omap_udc.c
+++ b/drivers/usb/gadget/udc/omap_udc.c
@@ -2593,9 +2593,22 @@ omap_ep_setup(char *name, u8 addr, u8 type,
 
 static void omap_udc_release(struct device *dev)
 {
-	complete(udc->done);
+	pullup_disable(udc);
+	if (!IS_ERR_OR_NULL(udc->transceiver)) {
+		usb_put_phy(udc->transceiver);
+		udc->transceiver = NULL;
+	}
+	omap_writew(0, UDC_SYSCON1);
+	remove_proc_file();
+	if (udc->dc_clk) {
+		if (udc->clk_requested)
+			omap_udc_enable_clock(0);
+		clk_put(udc->hhc_clk);
+		clk_put(udc->dc_clk);
+	}
+	if (udc->done)
+		complete(udc->done);
 	kfree(udc);
-	udc = NULL;
 }
 
 static int
@@ -2900,12 +2913,8 @@ static int omap_udc_probe(struct platform_device *pdev)
 	}
 
 	create_proc_file();
-	status = usb_add_gadget_udc_release(&pdev->dev, &udc->gadget,
-			omap_udc_release);
-	if (!status)
-		return 0;
-
-	remove_proc_file();
+	return usb_add_gadget_udc_release(&pdev->dev, &udc->gadget,
+					  omap_udc_release);
 
 cleanup1:
 	kfree(udc);
@@ -2932,36 +2941,15 @@ static int omap_udc_remove(struct platform_device *pdev)
 {
 	DECLARE_COMPLETION_ONSTACK(done);
 
-	if (!udc)
-		return -ENODEV;
-
-	usb_del_gadget_udc(&udc->gadget);
-	if (udc->driver)
-		return -EBUSY;
-
 	udc->done = &done;
 
-	pullup_disable(udc);
-	if (!IS_ERR_OR_NULL(udc->transceiver)) {
-		usb_put_phy(udc->transceiver);
-		udc->transceiver = NULL;
-	}
-	omap_writew(0, UDC_SYSCON1);
-
-	remove_proc_file();
+	usb_del_gadget_udc(&udc->gadget);
 
-	if (udc->dc_clk) {
-		if (udc->clk_requested)
-			omap_udc_enable_clock(0);
-		clk_put(udc->hhc_clk);
-		clk_put(udc->dc_clk);
-	}
+	wait_for_completion(&done);
 
 	release_mem_region(pdev->resource[0].start,
 			pdev->resource[0].end - pdev->resource[0].start + 1);
 
-	wait_for_completion(&done);
-
 	return 0;
 }
 
-- 
2.17.0

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 3/5] USB: omap_udc: fix omap_udc_start() on 15xx machines
  2018-11-24 22:17 [PATCH v2 0/5] omap_udc bug fixes Aaro Koskinen
  2018-11-24 22:17 ` [PATCH v2 1/5] USB: omap_udc: use devm_request_irq() Aaro Koskinen
  2018-11-24 22:17 ` [PATCH v2 2/5] USB: omap_udc: fix crashes on probe error and module removal Aaro Koskinen
@ 2018-11-24 22:17 ` Aaro Koskinen
  2018-11-24 22:17 ` [PATCH v2 4/5] USB: omap_udc: fix USB gadget functionality on Palm Tungsten E Aaro Koskinen
  2018-11-24 22:17 ` [PATCH v2 5/5] USB: omap_udc: fix rejection of out transfers when DMA is used Aaro Koskinen
  4 siblings, 0 replies; 6+ messages in thread
From: Aaro Koskinen @ 2018-11-24 22:17 UTC (permalink / raw)
  To: Felipe Balbi, linux-usb
  Cc: linux-kernel, linux-omap, Tony Lindgren, Aaro Koskinen

On OMAP 15xx machines there are no transceivers, and omap_udc_start()
always fails as it forgot to adjust the default return value.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
---
 drivers/usb/gadget/udc/omap_udc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/omap_udc.c b/drivers/usb/gadget/udc/omap_udc.c
index 240ccba44592..33250e569af8 100644
--- a/drivers/usb/gadget/udc/omap_udc.c
+++ b/drivers/usb/gadget/udc/omap_udc.c
@@ -2041,7 +2041,7 @@ static inline int machine_without_vbus_sense(void)
 static int omap_udc_start(struct usb_gadget *g,
 		struct usb_gadget_driver *driver)
 {
-	int		status = -ENODEV;
+	int		status;
 	struct omap_ep	*ep;
 	unsigned long	flags;
 
@@ -2079,6 +2079,7 @@ static int omap_udc_start(struct usb_gadget *g,
 			goto done;
 		}
 	} else {
+		status = 0;
 		if (can_pullup(udc))
 			pullup_enable(udc);
 		else
-- 
2.17.0

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 4/5] USB: omap_udc: fix USB gadget functionality on Palm Tungsten E
  2018-11-24 22:17 [PATCH v2 0/5] omap_udc bug fixes Aaro Koskinen
                   ` (2 preceding siblings ...)
  2018-11-24 22:17 ` [PATCH v2 3/5] USB: omap_udc: fix omap_udc_start() on 15xx machines Aaro Koskinen
@ 2018-11-24 22:17 ` Aaro Koskinen
  2018-11-24 22:17 ` [PATCH v2 5/5] USB: omap_udc: fix rejection of out transfers when DMA is used Aaro Koskinen
  4 siblings, 0 replies; 6+ messages in thread
From: Aaro Koskinen @ 2018-11-24 22:17 UTC (permalink / raw)
  To: Felipe Balbi, linux-usb
  Cc: linux-kernel, linux-omap, Tony Lindgren, Aaro Koskinen

On Palm TE nothing happens when you try to use gadget drivers and plug
the USB cable. Fix by adding the board to the vbus sense quirk list.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
---
 drivers/usb/gadget/udc/omap_udc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/gadget/udc/omap_udc.c b/drivers/usb/gadget/udc/omap_udc.c
index 33250e569af8..9b23e04c8f02 100644
--- a/drivers/usb/gadget/udc/omap_udc.c
+++ b/drivers/usb/gadget/udc/omap_udc.c
@@ -2033,6 +2033,7 @@ static inline int machine_without_vbus_sense(void)
 {
 	return machine_is_omap_innovator()
 		|| machine_is_omap_osk()
+		|| machine_is_omap_palmte()
 		|| machine_is_sx1()
 		/* No known omap7xx boards with vbus sense */
 		|| cpu_is_omap7xx();
-- 
2.17.0

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 5/5] USB: omap_udc: fix rejection of out transfers when DMA is used
  2018-11-24 22:17 [PATCH v2 0/5] omap_udc bug fixes Aaro Koskinen
                   ` (3 preceding siblings ...)
  2018-11-24 22:17 ` [PATCH v2 4/5] USB: omap_udc: fix USB gadget functionality on Palm Tungsten E Aaro Koskinen
@ 2018-11-24 22:17 ` Aaro Koskinen
  4 siblings, 0 replies; 6+ messages in thread
From: Aaro Koskinen @ 2018-11-24 22:17 UTC (permalink / raw)
  To: Felipe Balbi, linux-usb
  Cc: linux-kernel, linux-omap, Tony Lindgren, Aaro Koskinen

Commit 387f869d2579 ("usb: gadget: u_ether: conditionally align
transfer size") started aligning transfer size only if requested,
breaking omap_udc DMA mode. Set quirk_ep_out_aligned_size to restore
the old behaviour.

Fixes: 387f869d2579 ("usb: gadget: u_ether: conditionally align transfer size")
Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
---
 drivers/usb/gadget/udc/omap_udc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/gadget/udc/omap_udc.c b/drivers/usb/gadget/udc/omap_udc.c
index 9b23e04c8f02..fcf13ef33b31 100644
--- a/drivers/usb/gadget/udc/omap_udc.c
+++ b/drivers/usb/gadget/udc/omap_udc.c
@@ -2642,6 +2642,7 @@ omap_udc_setup(struct platform_device *odev, struct usb_phy *xceiv)
 	udc->gadget.speed = USB_SPEED_UNKNOWN;
 	udc->gadget.max_speed = USB_SPEED_FULL;
 	udc->gadget.name = driver_name;
+	udc->gadget.quirk_ep_out_aligned_size = 1;
 	udc->transceiver = xceiv;
 
 	/* ep0 is special; put it right after the SETUP buffer */
-- 
2.17.0

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-11-24 22:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-24 22:17 [PATCH v2 0/5] omap_udc bug fixes Aaro Koskinen
2018-11-24 22:17 ` [PATCH v2 1/5] USB: omap_udc: use devm_request_irq() Aaro Koskinen
2018-11-24 22:17 ` [PATCH v2 2/5] USB: omap_udc: fix crashes on probe error and module removal Aaro Koskinen
2018-11-24 22:17 ` [PATCH v2 3/5] USB: omap_udc: fix omap_udc_start() on 15xx machines Aaro Koskinen
2018-11-24 22:17 ` [PATCH v2 4/5] USB: omap_udc: fix USB gadget functionality on Palm Tungsten E Aaro Koskinen
2018-11-24 22:17 ` [PATCH v2 5/5] USB: omap_udc: fix rejection of out transfers when DMA is used Aaro Koskinen

This is a public inbox, see mirroring instructions
on how to clone and mirror all data and code used for this inbox